Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for a full stop in a variable! 2

Status
Not open for further replies.
Feb 16, 2003
87
0
0
GB
Hello all,

I'm using this to check that a form field contains something:

&error("Sorry, you must enter a domain name.") unless $FORM{'domain'};

but how can I change it that it will check for the presence of a full stop (period)?

The input must be in the format firstname.lastname so I guess I just need to check there's a full stop in it somewhere.

Any help greatfully received.

Simon
 
Hi Simon,

$name = 'michael.lacey';

if($name =~ /\./){
print "found a .\n";
} else {
print "not a . in sight\n";
} Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Hi Mike,

Thanks for that.

I assume that if($name =~ /\./) checks that there IS a . but how could I change to check that there ISN'T a . ????

Simon
 
use !~ instead of =~ for a negative match ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Cheers - OK, any ideas why this ain't working :)

&error('.name domains must be in the format firstname.lastname') if($FORM{'domain'} !~ /\./) && ($FORM{'tld'} eq ".name");

I've also tried:

&error('.name domains must be in the format firstname.lastname') if($FORM{'domain'} !~ /\./ && $FORM{'tld'} eq ".name");

Simon
 
Try

if(($FORM{'domain'}!~ /\./) && ($FORM{'tld'} eq ".name"))
{
&error('.name domains must be in the format firstname.lastname');

}

Don't see why that shouldn't work,

Regards

Ryan
 
Both !~ and eq have a higher precedence than &&, so Ryan's example should evaluate the same as Simon's second. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top