Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Tweak for my Perl Regex that screens for digits only

by radiantmatrix (Parson)
on Jan 27, 2006 at 18:37 UTC ( [id://526046]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # true if $string consists solely of allowed chars (and isn't empty)
    $string =~ m/^[\s\d-\(\)\.]+$/;
    
    # or, we could be true if $string contains anything except allowed cha
    +rs
    $string =~ m/[^\s\d-\(\)\.]/;
    
  2. or download this
    $string =~ m/^[\s\d-\(\)\.x]+|(?:[Ee]xt[\.]*)*$/;
    
  3. or download this
    sub is_valid {
        # check to see if an entry consists of valid "phone number" chars.
    ...
        # Ext or ext or x and digits.
        return ( $phone =~ m/^\d+(?:(?:[Ee]xt)|x)*\d$/ );
    }
    
  4. or download this
    unless ( is_valid($FORM{'phone'} ) {
        send_error("$FORM{'phone'} doesn't meet validity test");
        exit;
    }
    
  5. or download this
    $phone =~ m{^\d+[\d\-\.\s\(\)]+(?:(?:[Ee]xt[\.]*)|x)*\d$};
    
  6. or download this
    # valid number
    unless ($FORM{'phone'} =~ /^\d+[\s\d-\(\)\.]+$/) {
    ...
       # don't die if zero-length!
       die "Bad ext" if length($FORM{'ext'});
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://526046]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-03-28 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found