Link to home
Create AccountLog in
Avatar of SwamyN
SwamyN

asked on

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

How to check the decimal & alphabets in a string using javascript?
Ex: AB123FC
Numerals: 123
Alphabets: ABFC
Avatar of bugs021997
bugs021997
Flag of India image

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...
ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account