Posted on 2011-03-18
Last Modified: 2012-05-11
hey guys, i need a javascript to for validating integer number in a textbox or the pattern for rex editor?

here is one for decimal

function DecimalValidator(source, args)
    var Value = document.getElementById(source.controltovalidate).value;  
    var pattern = /^\d+(\.\d{1,2})?$/  
     if (!pattern.test(Value))  
            args.IsValid =false;
            document.getElementById(source.controltovalidate).className=  "errorbox";
            args.IsValid = true;
Question by:JCWEBHOST
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 40

Accepted Solution

gurvinder372 earned 167 total points
ID: 35164296
how many digits before the decimal and how many after the decimal is required?
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 166 total points
ID: 35164320
Now you want only for Integer no decimals

function IsNumeric(strString)
   //  check for valid numeric strings      
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         blnResult = false;
   return blnResult;

LVL 40

Expert Comment

ID: 35164375
function isNumeric(string)
   if ( parseInt(string) != null && parseInt(string) != undefined )
     return true;
     return false;
LVL 40

Expert Comment

ID: 35164377
LVL 82

Assisted Solution

leakim971 earned 167 total points
ID: 35165681
var pattern = /\D/
if (pattern.test(Value)) 

Open in new window


Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

705 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