Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
I have text field with regular expression.
I want to validate the field on blur, not on keyup event.

I tried following:
$('#txtMinRange[data-val-regex-pattern]').keyup(function () { return false });

But it does work for first time, but when the user tries to edit value the validation runs for keyup

Any idea, how to go about it?

Thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 2-Feb-15 10:51am    
Go about what? What works for the first time. You added a keyup handler, which does next to nothing, so what? Anyway, it should be added only once.
—SA
dhage.prashant01 2-Feb-15 23:01pm    
In short, I want to run data annotation validation on Blur not on KeyUp of the control.
Any way to do it?

1 solution

dhage.prashant01 asked:
In short, I want to validate the control on Blur not on KeyUp
Any way to do it?
Of course.
JavaScript
someElement.onblure = function() { /* some validation here */ }

With jQuery, this is even simpler: http://api.jquery.com/blur[^].

Any problems?

—SA
 
Share this answer
 
v2
Comments
dhage.prashant01 3-Feb-15 1:14am    
Sorry, I have updated the comment.
Sergey Alexandrovich Kryukov 3-Feb-15 2:40am    
I already answered. "Runs for the first time" is nonsense. It is supposed to be run only once.
Is "return true" is the real thing you returned? Why?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900