RegExp check for nothing or pattern

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
 
C

Carsten Aulbert

Hi Eric,
if ($data =~ m/{0}|\d{11,}/) { etc etc
Try this
/^\s*(|\d{11,})\s*$/

Grouping in perl is done with parentheses. I also added extra whitespaces
which might be around your number (or your "nothing")

If you want to use 0 as well, try
/^\s*(|0|\d{11,})\s*$/

And of course, read more under 'man perlre'

HTH

Carsten

PS: Have you asked the owner of nowhere.com if you are alowed to use their
domain name for email? Just asking, because it looks like you use it as a
pseudo anti-spam address.
 
G

Gunnar Hjalmarsson

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

/^(?:|\d{11,})$/
 
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 posted my answer to your other post entitled: "RegExp to match pattern or
BLANK?"

Why did you post the same question twice with two different subject lines?
 
E

Eric

I posted my answer to your other post entitled: "RegExp to match pattern or
BLANK?"

Why did you post the same question twice with two different subject lines?

For the sole purpose of annoying you.
 
T

Tad McClellan

Eric said:
For the sole purpose of annoying you.


(and *thousands* of people around the world. Your selfishness is astounding)


Goodbye troll.

*plonk*
 
E

Eric

Jeez you guys take this so seriously don't you!

It wasn't _really_ to annoy him, it was a simple mistake. My comment was an
example of what's referred to as 'sarcasm'. Perhaps you've not come across
it.

Get a grip guys!

Eric
 
S

Sam Holden

Jeez you guys take this so seriously don't you!

It wasn't _really_ to annoy him, it was a simple mistake. My comment was an
example of what's referred to as 'sarcasm'. Perhaps you've not come across
it.

Get a grip guys!

A remarkably foolish thing to do. Since things like sarcasm tend not
to work very well in usenet and email (hence the use of "smileys"), due
to the lack of tone of voice, facial expression, etc, etc.

This newsgroup is very high volume, and a large number of the most
knowledgable and helpful posters use killfiles, so that they won't
be overwhelmed by the garbage. They know that there is some
"collateral damage", but also know that ignoring some reasonable posts
is better than ignoring all posts (because the volume it too high).

Welcome to the "collateral damage" group.
 

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,011
Latest member
AjaUqq1950

Latest Threads

Top