Peter C
Peter C

Reputation: 47

bootstrap form input accept text only

Trying to create a contact form and realized that in the name input box, any character (ie. ~ / % @ # and etc.) and numbers can be entered.

<form>
  <label class="control-label" for="name">Full Name</label>
  <input type="text" class="form-control" name="name" id="name" maxlength="30">
</form>

Is there a bootstrap class or jQuery function that I can add to restrict the name input box to only the 26 alphabet? (Or at least no numeric value allowed...) Any help would be appreciated :)

Upvotes: 2

Views: 6226

Answers (1)

DDan
DDan

Reputation: 8276

You can do it with some jquery. Something like this: http://jsfiddle.net/ddan/ka52kdLv/2

<input class="alphaonly">
$('.alphaonly').bind('keyup blur',function(){ 
    var node = $(this);
    node.val(node.val().replace(/[^a-z ]/g,'') ); }
);

Or for a beautiful solution you can take a look for some validation libs.

Upvotes: 2

Related Questions