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?
 
Bryan ButlerConnect With a Mentor Commented:
The "+" should take care of the blank.  If you're using javascript:

^\d{1,}$
0
 
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.