Pages

Tuesday, 27 August 2013

Common regular expression in ASP .Net

Regular expression for mobile number should be start from 7 or 8 or 9
regular expression that should accept Indian mobile numbers. for example...
9788812345
9876512345
7891234567
8122212345
Syntax :
[789][0-9]{9}
Prefixing an optional (+91|0)? could make it more usable.

Regular expression for email , should be taking only numeric domain name like:

abc133@jhjh.dfsd : True
456@jhj.hh : True
8678@656.687 : False
hgh@679.vhhv : False
hgh@jbnj.656 : False

Syntax :
"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-a-zA-Z]+[.])+[a-zA-Z]{2,6}$"

Wednesday, 21 August 2013

One-liner if statements, how to convert this if-else-statement

Syntax :
return (expression) ? value1 : value2;
If value1 and value2 are actually true and false like in your example, you may as well just

return expression;
or
<result> = <condition> ? <true result> : <false result>;
Example :
string result = 5 > 10 ? "5 is greater than 10." : "5 is not greater than 10.";