Wednesday, April 30, 2014

Remove special character

<script language="javascript" type="text/javascript">
          function RemoveSpecialChar(u_name) {
            u_name.value = u_name.value.replace(/[ \/ , {} [ \] % @ # ! $ & * ` \\ ~ + = " ; ? ( ) | < > ' ^ :-]+/g, "");
           }
   </script>



<s:textfield name="u_name" cssClass="input_field"  javascript:RemoveSpecialChar(this); valid(this)"></s:textfield>

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>