Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2416
  • Last Modified:

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
0
SwamyN
Asked:
SwamyN
  • 2
1 Solution
 
bugs021997Commented:
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;  
   }
     

0
 
bugs021997Commented:
ooops...my bad don't use the comment i posted above...
0
 
Jim CakalicSenior Developer/ArchitectCommented:
var str = 'AB123FC';
var numbers = str.replace(/[^0-9]/g, '');
var letters = str.replace(/[^A-Za-z]/g, '');
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now