Monday, 27 June 2011

Check is any special character is exists in a string Through JavaScript


function CheckIsSpeciailCharExist(obj)
{
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
      for (var i = 0; i < obj.value.length; i++)
      {
         if (iChars.indexOf(obj.value.charAt(i)) != -1)
         {
            alert("Special characters not allowed.");      
            obj.value="";
            obj.focus();
          return false;  
          }
      }   
}

No comments:

Post a Comment