Alpha Numeric And Few Special Character Allowed Validation


Wednesday, August 3, 2011

Hello Friends,

jQuery provides you alphanumeric validation or only Special Character validation, below code will help you validate your textbox with alphanumeric and also allow few special character, you can see regex pattern below, you can add your special character which you want to allow..you can also see live demo by entering your text in below textbox.. 


Demo



Enter Name :


Note : Few character allowed (!,\-,.,&,*,#,@,/)




<html>
<head>
<title>jQuery test page</title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

<script type="text/javascript">
function loadContent() {

            if(validate()){
            document.getElementById('error').innerHTML="Validate Success.";
            document.getElementById("error").setAttribute("style", "color:Green;"); 
            }
            else{
            document.getElementById('error').innerHTML="Not Validate, its wrong.";
            document.getElementById("error").setAttribute("style", "color:Red;"); 
            }
}

function validate()
{
    return /^([a-zA-Z 0-9]([a-zA-Z 0-9\s\[\]\!\(\)\-\.\&\*\#\@/\\(/)/)])+$)/.test(document.getElementById('txtcheck').value);
}
</script>
</head>
<body>
Enter Name : <input type="text" id="txtcheck" onblur="loadContent()" />
<span id="error"></span><br />
Note : Few character allowed (!,\-,.,&,*,#,@,/)
</body>
</html>





Thanks
Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com

1 comment :

Anonymous said...

hello, what's new, what's up?