Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex validation for toll free number in USA.

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one suggest me regex for toll free number validation for USA?
 
Walter Gabrielsen Iii
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how refined you want it to be. I suggest that you should look at the description table in the java.util.regex.Pattern class under the section "Predefined character classes."

Then, for format, look at the Wikipedia page: Toll-free telephone number: North America
 
fred rosenberger
lowercase baba
Bartender
Posts: 12266
36
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us what you consider a toll free number in the U.S.A.? Where are you calling from? Do you need the country code prefix? do you need to dial '9' first to get an outside line? do you want to allow for the parens that often go around the area code?

What makes a number toll free? From where I sit, any number in the 314 area code is toll free (since that's where I live), but that may not be true for someone else.

My larger point is that the trick to defining the regex is to first understand what it is, EXACTLY, that you want to match. Tell us what, EXACTLY, you think a USA toll free number should look like.

Note that simply giving one example does NOT do that. giving ten examples does not do that. A thousand might, but would also probably still not be complete. think about corner and end cases - those are always the tricky one.
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All!

Fred,

I will try to come up with better explanation on this and hopefully get help on that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic