Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to write a javascript validation to a textbox which allows,
only alphabets,
no numeric,
no special symbols,
only one space between words,
no first char as space.

for exam:
name as ram kumar sripada

only one space between words and strating letter should be alphabet
Posted
Comments
What have you tried so far?

Use jQuery[^] with jQuery Validation Plugin[^] for easily add validation code...
For your exact rule use regexp...
 
Share this answer
 
Comments
Joezer BH 25-Feb-14 4:33am    
5ed!
May this Help You


HTML
<input type = "text" id = "txtState" />
<input type = "button" id = "btnValidate" value = "Submit" />


JavaScript
<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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900