I would like to know how do I validate a field name, to accept:
- Letters (Uppercase and Lowercase)
- Numbers
- Spaces
- Maximum 30 characters
- There can be no double space
- There can be no space at the beginning and at the end (As in the End the over name will have to have space, then it will not be necessary, as I will validate with trim later)
Code
$("[name=nome_p]").keyup(function() {
var $this = $( this ); //armazeno o ponteiro em uma variavel
var valor = $this.val().replace(/[^a-z0-9 ]+/gi,'');
$this.val( valor );
});