Friday, 15 January 2010

asp.net - Having some trouble with a custom validator using jquery -



asp.net - Having some trouble with a custom validator using jquery -

i'm having issue getting custom validator work jquery.

here function created check , see if textbox contains po box.

function valpobox(sender, args) { var haspobox = "^p\.?\s?o\.?\sb[oo][xx]."; var streetaddress = $('.streetaddress').val(); var match = streetaddress.match(regexp(haspobox)); if (!match) { args.isvalid = false; sender.errormessage = "address must not contain p.o. box"; $('.valpobox').attr("errormessage", sender.errormessage); } else { args.isvalid = true; } }

the function fires when tab out of textbox , follow logic args.isvalid = false; not display error message.

any ideas i'm doing wrong?

the lastly line have $('.valpobox').attr("errormessage", sender.errormessage); isn't valid code. attr function sets html attribute on element. i'm guessing want add together piece of text after input , show user 1 time has failed validation.

for example, have this:

<input class="streetaddress" /><span id="poboxerror"></span>

your js turns like:

... $('#poboxerror').html(sender.errormessage); } else { args.isvalid = true; $('#poboxerror').html(''); }

this sets span after input error message, , hides 1 time again 1 time has passed validation. 1 of ways accomplish this, other ways involve showing , hiding content, tried create reply close original code possible.

jquery asp.net regex customvalidator

No comments:

Post a Comment