• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

text box on blur validation for empty field

hello,
I am using following script to make sure in the text box that when I leave it ... it allows does not allow anything else than numeric. Numbers are allowed only. Empty string should be allowed but when user leave the text box the empty string should be converted to zero automatically.
How can I do this>>>
When user leaves the text box the empty string is replaced by Zero (0) Digit.
This is what I have >>>
onBlur="if (/\D/.test(this.value)){alert('Please enter the digits only');this.focus()}""
Regards,
0
pinaldave
Asked:
pinaldave
  • 2
1 Solution
 
ColosseoCommented:
Hi

You could change your onBlur to add this

if(this.value==''){this.value=0}

so

onBlur="if (/\D/.test(this.value)){alert('Please enter the digits only');this.focus()};if(this.value==''){this.value=0};"

HTH

Scott
0
 
pinaldaveAuthor Commented:
Thank you very much for quick and correct answer.
Regards,
---Pinal
0
 
ColosseoCommented:
Your very welcome, thank you for the grade.

Cheers

Scott
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now