Validation to Allow only Alphabets and Space using Regular Expression and JavaScript

Last Reply on May 02, 2013 06:19 AM By Mudassar

Posted on May 02, 2013 05:36 AM

how to put validation for city or state text box using mvc razor or jquery

ex: city text box has to accept only strings and it has to allow space like "andhra pradesh" 

 

Posted on May 02, 2013 06:19 AM

This way

    <input type = "text" id = "txtState" />
    <input type = "button" id = "btnValidate" value = "Submit" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type = "text/javascript">
        $("#btnValidate").live("click", function () {
            var regex = /^[a-zA-Z ]*$/;
            if (regex.test($("#txtState").val())) {
                alert("Valid");
            } else {
                alert("Invalid");
            }
        });
    </script>

Demo

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html