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

    Join Date
    Nov 2012
    Posts
    27
    Rep Power
    0

    RegEx for Empty textbox but also check for spaces and tabs


    Hello,

    I need the help of the experts on this forum.

    I would like to come up with a RegEx (javascript) to validate a textbox which has any blank spaces in it, any blank tabs in it, and also check for an empty textbox?

    ie.
    alert("Accepted")
    ------------------------------
    Jameswithsometext
    Billy Jean

    alert("Not accepted")
    ------------------------------
    - inadvertenly typed blank spaces
    - inadvertenly typed tabs
    - blank textbox
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,068
    Rep Power
    9398
    Easiest would be to find a non-whitespace character and negate the check, like
    Code:
    !/\S/.test(...)
    Or there's the more literal "contains only whitespace if anything at all",
    Code:
    /^\s*$/
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    27
    Rep Power
    0
    Thanks so much. Worked like a charm

IMN logo majestic logo threadwatch logo seochat tools logo