Solved

Javascript validation for numeric or null

Posted on 2013-05-10
3
314 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquey and footrable 2 35
jQuery Syntax 2 47
Regular Expression 1-100 with two digits 15 22
Recordset containing single quotes 8 21
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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now