I'm trying to create a Regex test in JavaScript that will test a string to contain any of these characters:
!$%^&*()_+|~-=`{}[]:";'<>?,./
More Info If You're Interested :)
It's for a pretty cool password change application I'm working on. In case you're interested here's the rest of the code.
I have a table that lists password requirements and as end-users types the new password, it will test an array of Regexes and place a checkmark in the corresponding table row if it... checks out :) I just need to add this one in place of the 4th item in the validation
array.
var validate = function(password){
valid = true;
var validation = [
RegExp(/[a-z]/).test(password), RegExp(/[A-Z]/).test(password), RegExp(/\d/).test(password),
RegExp(/\W|_/).test(password), !RegExp(/\s/).test(password), !RegExp("12345678").test(password),
!RegExp($('#txtUsername').val()).test(password), !RegExp("cisco").test(password),
!RegExp(/([a-z]|[0-9])\1\1\1/).test(password), (password.length > 7)
]
$.each(validation, function(i){
if(this)
$('.form table tr').eq(i+1).attr('class', 'check');
else{
$('.form table tr').eq(i+1).attr('class', '');
valid = false
}
});
return(valid);
}
Yes, there's also corresponding server-side validation!
.addClass("check")
and.removeClass("check")
? And seeingif (someBoolean == true)
in code always makes me cringe. Just doif (someBoolean)
. Or, better yet, just do$(".form table tr").eq(i+1).toggleClass("check", !!this); valid = valid && !!this;
.