Thursday, August 14, 2014

Check if string contains special characters or not using jQuery

This is very simple javascript code.it is used to check if string contains special characters or not.

Step 1: Need library file to perform empty action.Please copy and Paste below library file.

jQuery Function

<script type="text/javascript">
        $(function () {
            $('#btncheck').click(function () {
                var txt = $('#txtValue').val(); //Entered Value
                if (/^[a-zA-Z0-9- ]*$/.test(txt) == false) {
                    alert('Your String Contains illegal Characters');
                }
                else
                {
                    alert('Your String Not Contains illegal Characters');
                }
            })
        })
    </script>

HTML

Enter Your Text:
    <input type="text" id="txtValue" />
    <input type="button" id="btncheck" value="Check" />

Please share your comments and feedback.Thanks.Please subscribe my updates via email.

No comments:

Post a Comment