Here is the updated Jquery code:
$(document).ready(function() {
$("#username").on('focusout',function(){
var username = $("#username").val().trim();
if(username==="")
{
$("#usernameerrortext").html("Username should not be empty");
return false;
}
else if(/[!@#$%\^&*(){}[]<>?/|-]/.test(username))
{
$("#usernameerrortext").html("Username should not contain special charatcers");
return false;
}
else
{
$("#usernameerrortext").html("");
return true;
}
});
$("#password").on('focusout',function(){
var password = $("#password").val().trim();
if(password==="")
{
$("#passworderrortext").html("Password should not be empty");
return false;
}
else
{
$("#passworderrortext").html("");
return true;
}
});
});
I have created a demo fiddle for you here is the FIDDLE
You need to include the jquery lib in head tag of the page you want to run this script.
For that nothing much has to be done just add this line in the head tag <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…