repzero
repzero

Reputation: 8412

Does Javascript RegExp support POSIX expressions?

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,}/));

Upvotes: 14

Views: 6770

Answers (2)

royb
royb

Reputation: 119

POSIX character classes are not supported, but you can find JavaScript equivalents to them here:

http://www.regular-expressions.info/posixbrackets.html

Upvotes: 2

Jeff Bowman
Jeff Bowman

Reputation: 95654

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.

Upvotes: 14

Related Questions