We help IT Professionals succeed at work.

How to check the decimal & alphabets in a string using javascript?

SwamyN
SwamyN asked
on
2,446 Views
Last Modified: 2008-01-09
How to check the decimal & alphabets in a string using javascript?
Ex: AB123FC
Numerals: 123
Alphabets: ABFC
Comment
Watch Question

To check decimals use this....

use regular expression. try this:

function isDecimal(field)
{

var validTxt = /^[0-9.]+$/
var msg = "Not a valid decimal.";
if (! validTxt.test(field.value))
{
alert(msg);
return false;
}
else
{
return true;
}
}


or you can have this code instead:


   function IsNumeric(sText, name)
   {
    var iNumber=(sText)*(-1)*(-1);
    var IsNumber=(!isNaN(iNumber));
    if (IsNumber == false) {
         alert("Please enter NUMBER only for "+name+"!");
    }
    return IsNumber;  
   }
     

ooops...my bad don't use the comment i posted above...
Senior Engineer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.