regex for numbers only

what is the regex to check if a input is only numbers for example a telephone number must only have telephone numbers not digits.  The regex should only work if something is entered.  

Please explain example
enigma1234567890Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saikapian_4739Commented:
If u want to check only for numbers the following with work.

^[0-9]*$

This will make sure that the input starts and ends with numbers only and at the same time will check that the input contains only numbers b/w 0-9 no matter how many times they come.

Like regex will work for 4578, 12 578978787 but not t5656, 6767y, 767hju767, and for any other input that will contain anything other than a number.
0
enigma1234567890Author Commented:
didnt work only checks for all digits  not 666h or 445ft44
0
Bryan ButlerCommented:
That should not match 666h, unless something is fishy in denmark.  it would match blanks though.  A '+' should fix that:
^[0-9]+$

What regex rules are you using.  Same as this link?

http://regexlib.com/CheatSheet.aspx
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Bryan ButlerCommented:
Also if you post the exact code/command/sample, that might help.
0
enigma1234567890Author Commented:
its in a javascript and looks like.  I added {1,} to make sure blank requests dont get called

^[0-9]{1,}
0
enigma1234567890Author Commented:
not if I enter 66666666 or abcdefg it work
0
Bryan ButlerCommented:
The "+" should take care of the blank.  If you're using javascript:

^\d{1,}$
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
enigma1234567890Author Commented:
so what should it look like with the + ???
0
Bryan ButlerCommented:
^\d+$

The {1,} or the + should be interchangeable.

0
enigma1234567890Author Commented:
doesnt work  I think the sintax is right so will close question and opena s a javascript qustion to see what is wrong with code
thanks all
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.