Win a copy of Murach's Python Programming this week in the Jython/Python forum!
    Bookmark Topic Watch Topic
  • New Topic

regular expression example  RSS feed

 
anagha pendse
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am looking for a regular expression example to validate the Phone number

Could someone point me to such an example using the RegEx in Java1.4 ?

Thanks in advance,
-anagha
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Report post to moderator
Here's a great regexp reference.

As to your question ...

U.S. phone numbers? Spanish? Thai?
With dashes or without? Dots intsead of dashes?
International? With the + at the front?

If you give us a sample of the format it must match (e.g. 999-999-9999) then we could assist you. Otherwise, here's a regexp for a standard U.S. phone number (see above): "^\\d{3}-\\d{3}-\\d{4}$". The double \'s is to escape them in the Java String literal. The true pattern is "\d" but must be escaped when putting them into a Java String literal.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is a crosspost. Please continue discussion here: http://www.coderanch.com/t/326703/java/java/regular-expression-example-telephone-number
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!