Monday, January 6, 2014

Remove Special Characters from Textbox Using JavaScript

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Remove Special Characters from the Textbox using JavaScript</title>
<script language="javascript" type="text/javascript">
function RemoveSpecialChar(txtName) {
if (txtName.value != '' && txtName.value.match(/^[\w ]+$/) == null) {
txtName.value = txtName.value.replace(/[\W]/g, '');
}
}
</script>
</head>
<body>
<div>
<b>Enter Text:</b><input id="txtName"  type="text" onkeyup="javascript:RemoveSpecialChar(this)" />
</div>
</body>
</html>