newb: help me troubleshoot this regex plz? (c'mon it'll be fun!)

L

lover

\({0,1}(?<areacode>[0-9]{3})\){0,1}( /-){0,1}(?<prefix>[0-9]{3})(
/-){0,1}(?<suffix>[0-9]{4}).*

for matching phone numbers and replacing them with

(${areacode}) ${prefix}-${suffix}

it works awesome! if i type '8005551212' i get '(800) 555-1212'

the problem is, if i type 80055512121212121212, i also get '(800)
555-1212' ... but what i want to get instead is, 'no match'

how?

THANKS! =)
 
C

casanova

put an entry validation event to accept 15 characters only
prior to matching to area code prefix suffix. what if
there's extension # or more than one telephone #s in this
same field.

hth
p... cutter
-----Original Message-----
\({0,1}(?<areacode>[0-9]{3})\){0,1}( /-){0,1}(?
/-){0,1}(?<suffix>[0-9]{4}).*

for matching phone numbers and replacing them with

(${areacode}) ${prefix}-${suffix}

it works awesome! if i type '8005551212' i get '(800) 555-1212'

the problem is, if i type 800 555 1212 1212121212, i also get '(800)
555-1212' ... but what i want to get instead is, 'no match'

how?

THANKS! =)




.
 
B

Brian Davis

I am not positive that I understand your question, but removing the ".*"
from the end and wrapping your expression in "^...$" will make sure that the
input is exactly one valid phone number with nothing else:

^\({0,1}(?<areacode>[0-9]{3})\){0,1}(
/-){0,1}(?<prefix>[0-9]{3})(/-){0,1}(?<suffix>[0-9]{4})$


Brian Davis
www.knowdotnet.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top