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">


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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
Have a look at this fiddle. It's jQuery. Hope that's okay.
goodkAuthor Commented:
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
Tom BeckCommented:
You mean before submit of the form? Not that I'm aware of. It's like "placeholder". it's built into the browser engine for most browsers. Pattern does not work in Safari so it's not something I would use in a live site anyway.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goodkAuthor Commented:
so why cant i just do the regular expression in javascript.?
Tom BeckCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.