Solved

javascript

Posted on 2011-03-18
5
265 Views
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";
           
        }
        else
        {
            args.IsValid = true;
            document.getElementById(source.controltovalidate).className='correctbox';
        }
}  
0
Comment
Question by:JCWEBHOST
  • 3
5 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 167 total points
ID: 35164296
how many digits before the decimal and how many after the decimal is required?
0
 
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;
   }

refer
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26880094.html
0
 
LVL 40

Expert Comment

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

Expert Comment

by:gurvinder372
ID: 35164377
0
 
LVL 82

Assisted Solution

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

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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