Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numbers not allowed (0-9) - Regex Expression in javascript

I want a regex pattern which will allow me any chars, but it will not allow (0-9) numbers?

like image 654
Sanju Avatar asked Dec 14 '10 14:12

Sanju


People also ask

What is the regex represent 0 to 9?

The [0-9] expression is used to find any character between the brackets. The digits inside the brackets can be any numbers or span of numbers from 0 to 9. Tip: Use the [^0-9] expression to find any character that is NOT a digit.

What does the regex 0 9 ]+ do?

In this case, [0-9]+ matches one or more digits. A regex may match a portion of the input (i.e., substring) or the entire input. In fact, it could match zero or more substrings of the input (with global modifier). This regex matches any numeric substring (of digits 0 to 9) of the input.

What does 9 mean in regex?

In a regular expression, if you have [a-z] then it matches any lowercase letter. [0-9] matches any digit. So if you have [a-z0-9], then it matches any lowercase letter or digit.

Can you use regex with numbers?

The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. That's the easy part. Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999.


1 Answers

Simply:

/^([^0-9]*)$/ 

That pattern matches any number of characters that is not 0 through 9.

I recommend checking out http://regexpal.com/. It will let you easily test out a regex.

like image 153
jjnguy Avatar answered Oct 13 '22 21:10

jjnguy