Saturday, August 20, 2011

Some Important Example or Regular expression in asp.net



Remove last two zero inside gridview if
Price=56.0000:

'<%#Eval("Price").ToString().Remove(Eval("Price").ToString().Length - 2, 2) %>'


Regular Expressions for Amount:

^\$?\d+(\.(\d{2}))?$
To evaluate an amount with or without a dollar sign where the cents are optional.


^([0-9]*|\d*\.\d{1}?\d*)$
Accept only (0-9) integer and one decimal point(decimal point is also optional).After decimal point it accepts at least one numeric .This will be usefull in money related fields or decimal fields.

Regular Expression for multiline Textbox:

ErrorMessage="Address should be less than 130 characters" ValidationExpression="[\s\S]{0,130}"
ValidationGroup="submit">.


compare validate for today date:

Type="Date" runat="server" ValidationGroup="submit" ErrorMessage="Start date must be greater than today date."
SetFocusOnError="True">.



On page load

 c1.ValueToCompare = DateTime.Now.ToString("MM/dd/yyyy");


No comments:

Post a Comment