Solved

Javascript validation for numeric or null

Posted on 2013-05-10
3
316 Views
Last Modified: 2013-05-10
I have a page with 3 text boxes T1,T2,T3
I want to force the user to enter numeric values or a null

The following function works for the numeric part but I need to also accept if null

  function allnumeric(inputtxt)
   {
      var numbers = /^[0-9]+$/;
      if(inputtxt.value.match(numbers))
      {
      alert('Your new number has been accepted');
      document.Form_Edit.T1.focus();
      return true;
      }
      else
      {
      alert('Please input numeric characters only');
      document.Form_Edit.T1.focus();
        window.history.back()
      return false;
      }  
}
0
Comment
Question by:Mswetsky
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39155494
replace : if(inputtxt.value.match(numbers))
by : if(inputtxt.value.match(numbers)||inputtxt.value.length==0)
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39155498
How about this :

if(inputtxt.value.match(numbers) || inputtxt == null)

Open in new window

0
 
LVL 1

Author Closing Comment

by:Mswetsky
ID: 39155519
Thank you for the prompt reply. that works like a charm!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
age from date of birth 4 41
How can i  prevent default  Submision? 6 24
asp.net mvc5 6 15
Jquery Validation Messages Not Showing Up 3 6
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question