Mr.BK
Mr.BK

Reputation: 61

regex syntax of password validation not supported in mvc cshtml page

in script tag
      function ispwd() { 
            var pwdreg= ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$;  //here '^' and '\' are               shown invalid characters 
            var pwdval=$("#pwd").val();
            if(!pwdreg.test(pwdval))
            {        
            $("#pwd").after('<span class="error">the password must be 4-8 chars and include at least one upper case letter, one lower case letter, and one numeric digit.</span>');
            $("#pwd").focus();
            }
            }

in html
<p>Password<input type="password" id="pwd" onblur="ispwd()"/></p>

onblur from password the error says javascript error: 'ispwd' is not defined.

Upvotes: 0

Views: 517

Answers (1)

SLaks
SLaks

Reputation: 887315

Javascript regex literals must be enclosed in /.../ characters.

Upvotes: 1

Related Questions