javascript - jquery not recognizing $(this) -
i have following html , javascript:
html:
<div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3"> <div class="well"> <form id="registration-form" class="text-center" method="post" role="form"> <h1>registro</h1> <hr> <div class="form-group"> <label class="control-label" for="username">nombre de usuario</label> <input type="text" class="form-control" placeholder="nombre" name="username" id="username" autofocus> </div> <div class="form-group"> <label class="control-label" for="useremail">correo</label> <input type="email" class="form-control" placeholder="correo" name="useremail" id="useremail"> </div> <div class="form-group"> <label class="control-label" for="userpassword">contraseña</label> <input type="password" class="form-control" placeholder="contraseña" name="userpassword" id="userpassword"> </div> <hr> <button type="submit" name="cmdnewuserregister" id="cmdnewuserregister" class="btn btn-success">registrar</button> </form> </div> </div>
and following jquery:
var application = { init: function(){ $('#username, #userpassword, #useremail').on('keyup', isempty); $('#useremail').on('keyup', isemail); }, isempty: function(){ if($(this).val().length > 0){ $(this).parent().addclass('has-success').removeclass('has-error'); } else $(this).parent().removeclass('has-success').addclass('has-error'); }, isemail: function(){ var emailregex = new regexp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.)+(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.?$/i); if(emailregex.test($(this).val())){ $(this).parent().removeclass('has-error').addclass('has-success'); } else $(this).parent().removeclass('has-success').addclass('has-error'); } }; $(document).ready(function(){ //se inicializa el objeto: application.init(); //validación de correo });
apparently, isn't working since classes not applied. can spot problem, here pen it:
isempty
, isemail
not defined. you'll need replace them application.isempty
, application.isemail
, respectively.
Comments
Post a Comment