Link to home
Start Free TrialLog in
Avatar of goodk
goodkFlag for United States of America

asked on

How to check for Pattern if you have an event such as on

<input type="text" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code">


onmouseleave=showHint(this.value)

It appears that the event gets fired first before the pattern is tested.  It does check the pattern on form submit.  I however want it to test the pattern before firing the event on onmouseleeave, showHint.

How do we check for pattern before firing an event function?
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Have a look at this fiddle. It's jQuery. Hope that's okay.

http://jsfiddle.net/g0raydae/
Avatar of goodk

ASKER

Oh, I know about jQuery or using javascript in a function.

I was wondering if the pattern could be checked before calling the function?  

There is something missing in my understand of the html5 Pattern
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of goodk

ASKER

so why cant i just do the regular expression in javascript.?
You always have the option of using regular expression in JavaScript. The point of using pattern is to avoid using JavaScript. It will work even if the user has JavaScript turned off. But it triggers on submit, not on blur.

Thanks for the points.