I have a password <input>
box in a <form>
element my html body
When a user click on the submit button in the sign up form, I can get javascript to determine whether the string the user typed in the password box is a combination of alphabet and/ or numbers by using the following code
$("#password1").val().match(new RegExp(/[a-zA-Z1-9]{1,}/));
However when I tried using the expression below, it returns "null" which gives me the impression that POSIX expressions are not supported in javascript... or is it somewhere along the line I am missing something?
$("#password1").val().match(new RegExp(/[[:alnum:]]{1,}/));
POSIX bracket expressions are a special kind of character classes. POSIX bracket expressions match one character out of a set of characters, just like regular character classes. They use the same syntax with square brackets.
Using regular expressions in JavaScript. Regular expressions are used with the RegExp methods test() and exec() and with the String methods match() , replace() , search() , and split() . Executes a search for a match in a string. It returns an array of information or null on a mismatch.
RegExp Object A regular expression is a pattern of characters. The pattern is used to do pattern-matching "search-and-replace" functions on text. In JavaScript, a RegExp Object is a pattern with Properties and Methods.
E.g. (? i-sm) turns on case insensitivity, and turns off both single-line mode and multi-line mode.
Posix expressions such as :alnum:
are not supported, though some other backslash-escaped character classes (like \w
for word characters including alphanumeric characters and the underscore) are allowed.
POSIX character classes are not supported, but you can find JavaScript equivalents to them here:
http://www.regular-expressions.info/posixbrackets.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With