jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Regular Expression test failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular Expression test failure" Watch "Regular Expression test failure" New topic
Author

Regular Expression test failure

vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
I am testing a regular expression for telephone number validation. I am getting the desired results in all cases except in a few cases.
This test will work for phone numbers of format:
1)111-222-3333
2)111.222.3333
3)111 222 3333
4)111.222-3333 or 111-222.3333
5)1112223333
6)(111)-222-3333
7)(111).222-333 or (111)-222.3333
8)111 222 333
9)(111) 222 3333


But it works for numbers like: 111#222*3333.
Can anyone tell me what's wrong with the expression?

Thanks.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

A period (".") is a special character in regular expressions; it stands for "any character."


[Jess in Action][AskingGoodQuestions]
vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
Thank you. I escaped it and it works as it should.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular Expression test failure