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

    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    Regex Expression with special characters


    I want to allow numberic and alphacharacters. I don't want to allow "#$%^&*()'" characters.

    I've written that below and it seems to be working.

    ValidationExpression="^(a-z|A-Z|0-9)*[^#$%^&*()']*$"

    Now I want to add on top of that and don't allow these specific string characters: "amp;" "testing;"

    So if you type "this is a amp; test" - it won't allow it. or "this is # testing;"

    But if you type: "amp test" it will allow it.

    So how do I add the code to the validation expression to check and not allow the specific string characters I have above?
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,762
    Rep Power
    9397
    Regular expressions aren't really for that.
    Do your character check with a regular expression, then do separate checks for the various substrings.

    However, if you have a lot of them, regular expressions might be better - depends on the language.
    Code:
    ^((?!amp|testing);.)+$
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0
    Is there a way to combine mine and your code into 1 regular expression?

    When I just use ^((?!amp|testing);.)+$ it doesn't allow any characters. No numbers, letters anything.

    Originally Posted by requinix
    Regular expressions aren't really for that.
    Do your character check with a regular expression, then do separate checks for the various substrings.

    However, if you have a lot of them, regular expressions might be better - depends on the language.
    Code:
    ^((?!amp|testing);.)+$

IMN logo majestic logo threadwatch logo seochat tools logo