Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts

    Is not a number validation

    how do I check if a user has entered a number?
    Like I don't want them to enter a number

    so I'm trying to do

    PHP Code:
    else if($firstNameSignUp IS A NUMBER)) {
                
    $firstNameSignUpError "Your first name cannot be a number you entered " $firstNameSignUp;
                
    $firstNameSignUp "";
            } 
    how can I do this?
    Last edited by MrEnder; 03-22-2010 at 02:29 AM.
    Continually Learning

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    use is_int

    if(is_int($str)){
    echo 'number';
    }

  • #3
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    but then what if the user enters their name as 3.141592654, or s1, or even worse $ ?

    im now trying to work with

    if(!preg_match("/^[\w-]+$/", $firstNameSignup)) {
    $firstNameSignupError = "Your first name cannot contain numbers or symbols, you entered " . $firstNameSignup;
    $firstNameSignup = "";
    }

    but its not working =[
    Last edited by MrEnder; 03-22-2010 at 03:25 AM.
    Continually Learning

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    if (preg_match('#[^a-z]+$#i', $firstNameSignup)) {

  • Users who have thanked MattF for this post:

    MrEnder (03-22-2010)

  • #5
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by MattF View Post
    Code:
    if (preg_match('#[^a-z]+$#i', $firstNameSignup)) {
    you are slowly becoming my best friend lol thanks!!!

    Quote Originally Posted by MattF View Post
    Code:
    if (preg_match('#[^a-z]+$#i', $firstNameSignup)) {
    ok one more question...

    what if they could use numbers and letters but not symbols except - and _?

    oh ya and for e-mail

    how will that work

    letters+@+letters+.+2-4letters
    Last edited by MrEnder; 03-22-2010 at 04:14 AM.
    Continually Learning

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Numbers, letters, underscore and hyphen:

    Code:
    '#^[^\w\-]$#i'
    E-mail:

    Code:
    '#^[\w\.\+\-]{1,}@(?:[\w\-]+\.){1,}[a-z]{2,4}$#i'

  • Users who have thanked MattF for this post:

    MrEnder (03-22-2010)

  • #7
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    thank you once again your amazing ^.^

    dang the number one is not quite working =[

    its allowing symbols other then - and _
    Last edited by MrEnder; 03-22-2010 at 04:26 AM.
    Continually Learning

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by MrEnder View Post
    dang the number one is not quite working =[

    its allowing symbols other then - and _
    It can't be passing anything else. \w only covers underscore, letters and numbers.

    http://docs.google.com/viewer?a=v&q=...f9CE7_1IxdYnpA

  • #9
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by MattF View Post
    It can't be passing anything else. \w only covers underscore, letters and numbers.

    http://docs.google.com/viewer?a=v&q=...f9CE7_1IxdYnpA
    Ok I am here typing in my form and it allowes me to type

    Bobby@ or Tod&11

    when I use

    '#^[^\w\-]$#i'

    But I can't write

    @bobby
    Continually Learning

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Change it to:

    Code:
    '#[^\w\-]+#i'

  • Users who have thanked MattF for this post:

    MrEnder (03-22-2010)

  • #11
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by MattF View Post
    Change it to:

    Code:
    '#[^\w\-]+#i'
    brilliant thank you ^.^
    Continually Learning

  • #12
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    dang now how do I do this

    '#[^\w\-\.\,\!]+#i'

    allow letters numbers hyphens periods commas and exclamation marks

    nm my regex worked fine lol was something else casuing the error ^.^ (bad variable to check against lol)
    Last edited by MrEnder; 03-22-2010 at 05:01 AM.
    Continually Learning


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •