<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var txtvalue=$("#firstname").val(); if(isValid(txtvalue)){ alert("Name can have only specific chras only."); } else{ alert("Accepted.");} }); function isValid(str){ return /[_@.!$%^#&+-{}=^~`,;]/g.test(str); } }); </script> </head> <body> <button>Click to check special chars</button> <input type="text" name="Firstname" value="" id="firstname"> </body> </html>
/[^\w]|_/g
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)