There is a fundamental problem when trying to reorient a field to onblur if it is not valid. If the user decides to leave, simply cannot. When they leave the field, they are forcibly taken back. I have seen cases where a user is forced to kill his browser session, just to avoid overly diligent onblur .
I understand that this may not be the exact solution you need, but I can recommend a different approach, which still involves checking on the client side.
I recommend that you select the field as invalid in onblur . For instance. place a star next to you, highlight it in red, etc. This way you can do without alert , and the user still has control.
When a user arrives to submit a form, you perform your client-side checks and issue a warning on them (see @Phill Sacre answer)
source share