• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

regular expression:- validate string of numbers

hi guys

I am looking for a regular expression which will check if there are
any alphabets in a string of numbers.  
i am using

public function isValidNumber(s:String):Boolean{
return Boolean(s.match(/^[0-9]+$/));
}

if i enter s = 55e or s = 6567y  it returns false which is fine
but when i enter
s = 99.99
it returns false.

When decimal numbers example 99.99 is entered i want it to return true but when
99.aa is entered i want it to return false.

any idea how i can change my above function ?

thanks
0
royjayd
Asked:
royjayd
1 Solution
 
Terry WoodsIT GuruCommented:
This should do it:

public function isValidNumber(s:String):Boolean{
return Boolean(s.match(/^\d+(\.\d+)?$/));
}

Open in new window


If you'd also like to allow negative numbers, then use this pattern:

/^-?\d+(\.\d+)?$/

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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