RegExp to match pattern or BLANK?

E

Eric

Hi,

I want to write a regexp that matches either a blank value or a pattern. I'm
checking user data for a 'telephone' field which I want to allow to be blank
OR have at least 11 digits.

I've tried

if ($data =~ m/{0}|\d{11,}/) { etc etc

But it doesn't work

OK I know I can do it with some code, but my system reads regexps from a
config file and I'd like to keep my system versatile.

Cheers,

Eric

passme
 
M

Michael Zawrotny

I want to write a regexp that matches either a blank value or a pattern. I'm
checking user data for a 'telephone' field which I want to allow to be blank
OR have at least 11 digits.

I've tried

if ($data =~ m/{0}|\d{11,}/) { etc etc

Try

if($data =~ /^(\d{11,})?$/) { ...


Mike
 
D

David Oswald

Eric said:
I want to write a regexp that matches either a blank value or a pattern. I'm
checking user data for a 'telephone' field which I want to allow to be blank
OR have at least 11 digits.

I've tried

if ($data =~ m/{0}|\d{11,}/) { etc etc

But it doesn't work

OK I know I can do it with some code, but my system reads regexps from a
config file and I'd like to keep my system versatile.

m/^(?:\d{11,})?$/

That matches a string consisting optionally of eleven or more digits. It
will not match a string containing anything else, nor will it match a string
containing any number of digits less than eleven, except for zero digits.

If your phone number contains hyphens or paranthesis, you're going to have
to get more creative.

DaveO
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top