Sto cercando di verificare se un campo di input ha l'attributo "pattern" e in tal caso, preformare un controllo regex come detto schema. So che questo è già stato fatto da HTML5, ma voglio gestire l'evento me stessa. Sto ricevendo questo errore: TypeError Uncaught: Object a-zA-Z non ha un metodo 'test'Jquery Convalida Jquery
///Check Perform Reg///////////////////////////////////////////////////////
if ($(this).attr("pattern")) {
var reg = $(this).attr("pattern");
var currentValue = $(this).val();
if (reg.test(currentValue)) {
$(this).after($error.clone().text("Invalid Input.Try Again."));
$(".error:hidden").fadeIn("slow");
hasError = true;
return false;
}
}
///////////////////////////////////////////////////////////////////////////
Ancora nessuna fortuna,
anche qui è il mio html:
<div>
<input class="formInput" name="First Name" pattern="^[A-Za-z_-][A-Za-z0-9_-]*$" type="text" id="frmFirst" min="2" maxlength="30" required="required"/>
<span>First Name</span>
</div>
Sembra essere la stessa cosa che il mio codice già fa. eccetto che il modello è passato da una variabile – user1265533
sì sembra uguale, per le espressioni regolari è necessario racchiudere il modello all'interno di/[pattern]/e.g/test/per l'abbinamento con il test del valore. – irfanmcsd