regular expression:- validate string of numbers

Posted on 2012-09-06
Last Modified: 2012-10-02
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 ?

Question by:royjayd
    1 Comment
    LVL 34

    Accepted Solution

    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:


    Open in new window


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
    PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now