Friday 17 October 2014

How to apply Special character validation using Jquery

<input type="text" name="txtKeywords" id="txtKeywords" />
<input type="submit" value="Search" title="Search" id="btnSearch"  />

<script>
    $(document).ready(function () {
        $("#btnSearch").click(function () {

            var titleValue = $("#txtKeywords").val();

            // Apply check for special characters
            if ((/^[a-zA-Z0-9- ]*$/.test(titleValue) == false) ) {
                alert('Your String Contains illegal Characters.');
                return false;
            }
         
        });
    });
</script>

0 comments:

Post a Comment


                                                            
 
Design by Abhinav Ranjan Sinha