I will be the first to admit that I do not know much about regular expression, in javascript or anywhere else. Here's what I need to do.
I am verifying a supplied password to make sure it contains
at least one capital letter
at least one numeric
at least one special character (!@#$%^&*+)
is at least 8 characters
Here's the function I'm using currently.
var password = $('#password').val();
var re = new RegExp("!@#$%^&*");
if(!re.test(password))
alert("No special characters");
re = new RegExp("0123456789");
if(!re.test(password))
alert("No numbers");
This is just test code so please don't comment on how bad it is, I'm trying to get it to work before I make it pretty.
Right now, no matter what I type the code is saying that the password contains no numbers and no special characters.
Clearly I'm doing something wrong, but what is it?
Can anyone point me in the right direction? Thanks.
var password = $('#password');
//will check word disgit and mention special character in the password
var re = new RegExp("[!@#\$\%\^&\*\w\d]*");
if(!re.test(password))
alert("No special characters");
re = new RegExp("\d*");
if(!re.test(password))
alert("No numbers");
The RegExp constructor is not needed for this exercise but I have retained it:
Code:
<script type="text/javascript">
var password = '@2';
var re = new RegExp("[!@#$%^&*]");
if(!re.test(password))
alert("No special characters");
re = new RegExp("[0123456789]");
if(!re.test(password))
alert("No digits");
</script>
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
Bookmarks