victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
972 stars 476 forks source link

How to set a input field to allow only letters (no numbers) with support for international language #678

Closed RajuMenon closed 6 years ago

RajuMenon commented 6 years ago

This is for First Name and Last Name input fields which should support only letters and must also support all languages.

The "letternumeric" option allows numbers too which is not required in Name field. The other option is to use data-validation-regexp="^([a-z,A-Z]+)$" which only allows English alphabets and doesn't support foreign languages.

Please provide a solution for this.

victorjonsson commented 6 years ago

The regex should be ^([^0-9]+)$ and be used together with the validator letternumeric that comes with the security module.

http://jsbin.com/gaxuxuzufo/edit?html,output

RajuMenon commented 6 years ago

Thanks, that solved the issue.

Just adding the code here for anyone else who is facing this issue:

<input name="firstName" type="text" id="firstName" value="" class="form-control" tabindex="13" data-validation="required custom letternumeric" data-validation-regexp="^([^0-9]+)$" data-validation-error-msg="Please enter your first name" />