Link to home
Start Free TrialLog in
Avatar of pinaldave
pinaldaveFlag for India

asked on

multiple text box validation for int only onblur or mouse out...

hello Experts,
I have one form with many checkbox.
I would like to have javascript when mouse is moved out from that field or onblur ( which ever is correct you think) ... I want to validate that if that is int only...
if not alert 'pls enter int' how can I do that.
Regards,
---Pinal
Avatar of archrajan
archrajan

onblur = "if(isNaN(this.value)){alert('Please enter numbers');this.select;this.focus();}"
<input onchange="if (/\D/.test(this.value)){alert('integers only please');this.focus()}" onblur="this.onchange()">
this is better

<input onchange="if (/\D/.test(this.value)){alert('integers only please');this.focus()}">
Avatar of pinaldave

ASKER

Gwyn and Arch
Both works. Thank you very much.

<input onchange="if (/\D/.test(this.value)){alert('integers only please');this.focus()}"> how can I have focus back to the field which has the not an integer.
Thank you. It is moving the focus to where ever I have clicked. It should not let me enter any thing else than integer... cause it is moving the focus from that field and I can still submit it and my application is crashing.. somehow due to some complexity I am not able to use server side validation.

Regards,
---Pinal
ASKER CERTIFIED SOLUTION
Avatar of GwynforWeb
GwynforWeb
Flag of Canada 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
Arch Just tried your solution again...
it does not work.. thank you both of you for helping me... all the time...
I still need help.
Regards,
---Pinal
I think the above does it.
Thx for the points. :-)
<input onblur="if (/\D/.test(this.value)){alert('integers only please');this.focus()}">
works and good suggestion.
No.. I do not want float Just an integer...was working on server side validation for more than one hour.. this will do the same job...
Regards,
---Pinal
Look out for another Q which I will post in a min... pls...
Thank you.
---Pinal