Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression test failure

 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A period (".") is a special character in regular expressions; it stands for "any character."
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I escaped it and it works as it should.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic