4
I would like to know how to validate a name field, to accept:
- Letters (Upper and Lower Case)
- Numbers
- Spaces
- Maximum 30 characters
- There can be no double space
- There cannot be space at the beginning and at the end (As at the End the over name will have to have space, then it will not be necessary, because I will validate with Trim subsequently)
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 );
});