Skip to main content
gamedev.net
🔒 Locked

[.net] Regular Expression Problem

Started by coolblue Dec 5, 2005 at 11:52 AM 3 replies 450+ views
Original Post
coolblue
coolblue
I am using the following code to validate a uk 11 digit phone number. Regex expression=new Regex("/^([0-9]{11})$/"); Match m=expression.Match("12345678901"); if(m.Success==true) { return true; } else { return false; } this is not working though. Is this correct?
_DarkWIng_
_DarkWIng_
Try something like:
return Regex.IsMatch( "0123456789012", @"^([0-9]{11})$" );or evenreturn Regex.IsMatch( "0123456789012", @"^(\d{11})$" );
You should never let your fears become the boundaries of your dreams.
coolblue
coolblue
Thank you. Why do all the examples on the net show \^ and $/ instead of just ^ or $?
Ra
Ra
/^...$/ is the Perl way of doing regular expressions. They begin and end with /.
Ra
Sneftel
Sneftel
Becase regular expressions were first commonly used (IIRC) in sed, which bracketed them in slashes. Later, Perl (which is a common consumer of regexes) did the same by default.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.