Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
137
rated 0 times [  142] [ 5]  / answers: 1 / hits: 45576  / 13 Years ago, mon, march 14, 2011, 12:00:00

I am using a javascript validator which will let me build custom validation based on regexp



From their website: regexp=^[A-Za-z]{1,20}$ allow up to 20 alphabetic characters.



This will return an error if the entered data in the input field is outside this scope.



What I need is the string that will trigger an error for the inputfield if the value has an asterix as the first character.



I can make it trigger the opposite (an error if the first character is NOT an asterix) with:



regexp=[u002A]


Heeeeelp please :-D


More From » regex

 Answers
15

How about:



^[^*]


Which matches any input that does not start with an asterisk; judging from the example regex, any input which does not match the regex will be cause a validation error, so with the double negative you should get the behaviour you want :-)



Explanation of my regex:




  • The first ^ means at the start of the string

  • The [ ... ] construct is a character class, which matches a single character among the ones enclosed within the brackets

  • The ^ in the beginning of the character class means negate the character class, i.e. match any character that's not one of the ones listed

  • The * means a literal *; * has a special meaning in regular expressions, so I've escaped it with a backslash. As Rob has pointed out in the comments, it's not strictly necessary to escape (most) special characters within a character class


[#93301] Friday, March 11, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frederickmohamedw

Total Points: 21
Total Questions: 123
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
frederickmohamedw questions
Wed, Sep 23, 20, 00:00, 4 Years ago
Sat, Jul 18, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
Sat, Jan 11, 20, 00:00, 4 Years ago
Fri, Dec 27, 19, 00:00, 4 Years ago
;