Friday, 15 April 2011

Regex for Valid Email address or Valid alpha numeric check -


Hello, I have a field named Username in my MVC 3 model. This proposal may be a valid email address or be valid alphanumeric. How can I write Reggae Express to check both things (valid email or valid alpha numeric)

The valid email expression I am using

  "^ [_ _A-zA -Z0-9 \ '-] (\ [_ one-zA-Z0 -9 \. '-]) * @ [one-zA-Z0-9 -.] + (\ [One-zA-Z0-9 -] +) *. (([0-9] {1,3 }} | ([A-zA-Z] {2,3}) | (name)) $ "  assuming that instead of an email address you want to match the alphanumeric string, It's actually just  AZ  

0-9 , which you already have Only you can take ...
  ^ [_ a-zA-Z0- 9 \ '-] + (\. [_a-zA-Z0-9 \' -]) * @ [One-zA-Z0-9 -] (\ [one-zA-Z0-9 - ..] +) * (([0-9] {1,3}) | ([a-zA-Z ] {2,3}) | (name)] $   

... and wrap it in a bracket with a pipe to indicate it as an optional group ...

  ^ ([_ a-zA-Z0 -9 \ '-] + (\. [_A-zA-Z0-9 \' -] +) * @ [one-zA-Z0-9 -] (\ [one-zA-Z0-9 -]) * \ (([0-9] {1,3} ..) | ([A-GA-Z] {2,3}) | (name) | [A-GA-Z0-9] +) $   

Which looks like a very simplified solution, give that which you have done so far, which makes me wonder if there is something on it ???

No comments:

Post a Comment