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

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Add white space to regular expression


    Hi,

    I have these two regular expressions:
    @"^([1-9]\d{8})$"

    @"^([0-4][0-9][0-9])$"

    At the moment, if the user enters a space e.g. 22 22 22222, then it returns as invalid because the regular expressions don't accept any white space.

    I would like the user to be able to enter white spaces as well as not entering white space and the number being returned as valid.

    e.g. 22 22 22222 and 222222222

    Please can someone help me amend the above regular expressions so that they also allow the user to enter both white space and no white space?

    Thank you very much
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    As I've said to many people, for phone numbers it's a lot easier if you strip out invalid symbols and validate the rest. Specifically, remove all non-digits and check what remains. Then reformat it into whatever shape you want.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0
    hi,
    the regular expressions i posted above only accept numbers and nothing esle. however, i wanted to change it so that they accept white space as well.
    do you know how i can amend them to do this?
    thank you
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    Change the \d into a character set ([0-9] or [\d]) and add a space to all the character sets.

    What about hyphens? I enter phone numbers using hyphens.

IMN logo majestic logo threadwatch logo seochat tools logo