File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular Expression test failure" Watch "Regular Expression test failure" New topic

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:
3)111 222 3333
4)111.222-3333 or 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?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

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.
It is sorta covered in the JavaRanch Style Guide.
subject: Regular Expression test failure
It's not a secret anymore!