pTutorial

New way to learn Programming

Java Script special symbol validation with JQuery

JavaScript : HTML Form - special symbol validation

In this article we demonstrate the special character validation with the help of live example. The following JQuery Script can be used to check whether user has entered special character or not.

Regular expression for special symbol validation

function checkSpecialSymbol(data) {
var letters = /^[^a-zA-Z0-9 ]+$/;
if (data.match(letters)) {
return true;
} else {
return false;
}
}

JavaScript special symbol validation example

<!DOCTYPE html>
<html>
<head>
<script src="http://freeonlinecompiler.ptutorial.com/js/
jquery.min.js"></script>
<script>
$(document).ready(function (e) {
$('#kk').click(function () {
var z = $.trim($('#uk').val());
if(z==''){
$('#divData').html("Please enter Special symbol");
}else if (checkSpecialSymbol(z)) {
$('#divData').html("You have enter " + " " + z);
$('#uk').css("border-color", "green");
return false;
} else {
$('#divData').html("Only Special Symbol allowed here");
$('#uk').css("border-color", "red");
return false;

}
})
});
function checkSpecialSymbol(data) {
var letters = /^[^a-zA-Z0-9 ]+$/;
if (data.match(letters)) {
return true;
} else {
return false;
}
}
</script>
<style>
table{
border: 1px solid #080808;
margin: 5px;
padding: 10px;
}

</style>
</head>
<body>
<h4>Special symbol form Validation</h4>
<table id="tab">
<tr>
</tr>
<tr>
<td>Enter Name *</td>
<td> <input type="text" id="uk" name="kk1"></td>
</tr>
<tr>
<td> <input type="submit" id="kk" value="Check"></td>
</tr>
</table>

<div id="divData"></div>
</body>
</html>


Download

See Also


QUOTES OF THE DAY

Knowledge itself is a power.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER