I am trying to make an if statement that will test a string in jQuery (or Javascript). Here are the conditions:
- Has to be between 6-8 characters.
- First character cannot be a number.
- Has to contain 1 number, 1 lowercase letter, and 1 uppercase letter.
Here is my regex code:
((?=^[^0-9])(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,8})
I tested it on a website that tests regex codes, and it works fine.
Here is my if statement currently:
if(((?=^[^0-9])(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,8}).test(strOldPassword))
{
alert("Something");
}
I am getting a syntax error when my webpage loads however, saying that there is a problem with the regex.
Can someone help me find what I am doing wrong? Thanks.
There are two ways to define a regular expression in JavaScript.
Using the
/.../syntax.By creating an instance of RegExp object which accepts the regular expression as a String in the constructor.
That is,