enigma1234567890
asked on
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
Please explain example
ASKER
didnt work only checks for all digits not 666h or 445ft44
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-9]+$
What regex rules are you using. Same as this link?
http://regexlib.com/CheatSheet.aspx
Also if you post the exact code/command/sample, that might help.
ASKER
its in a javascript and looks like. I added {1,} to make sure blank requests dont get called
^[0-9]{1,}
^[0-9]{1,}
ASKER
not if I enter 66666666 or abcdefg it work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so what should it look like with the + ???
^\d+$
The {1,} or the + should be interchangeable.
The {1,} or the + should be interchangeable.
ASKER
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
thanks all
^[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.