Skip to content Skip to sidebar Skip to footer

Validation Based On A Regular Expression Only On Submit

I use a regular expression to validate a price, but the error message appears before I finish to insert the value. For example, I what yo insert the value '10.20', and when I get t

Solution 1:

Assuming this is a client-side (i.e. web browser) script, using something like onChange() or onBlur(), it should be easy enough to validate on the given event and detect the boolean outcome. However if you're using onChange() the validation will run as soon as you start typing, whereas if you were to use onBlur() the validation would only run after focus moves away from that input field. If you really want to use onChange() then you will need to code extra checks to periodically poll the contents (based on key-up detection perhaps) in order to allow time to type the full value. I'm not familiar with the syntax you have used so if you're coding within a framework rather than rolling your own then I can't comment any further. It's pretty standard stuff and usually with bugs like that it's something very simple and [eventually] obvious! Good luck.


Post a Comment for "Validation Based On A Regular Expression Only On Submit"