#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    I need regex to allow only numbers and not spaces


    Hi,
    I need a regex to accept only numeric characters and the plus symbol (+). Letters, or any other whitespace character should not be allowed.
    I have done lots of searching searching but so far have not found anything. I hope someone can help me.
    Thank you
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    "Only numeric characters and the plus symbol"? Actually quite simple.
    Code:
    /^[0-9+]*$/
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by requinix
    "Only numeric characters and the plus symbol"? Actually quite simple.
    Code:
    /^[0-9+]*$/
    thank you,
    it works
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Note that this will accept any combination of digits and the "+" as well as empty strings. So things like "++++++" will be considered valid. Not sure if that's what you want.

    Comments on this post

    • requinix agrees : to the letter
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo