![]() |
User input can contains?
If user input can contains numbers, slashes (-) and plus sign but nothing else, how do I check that?
Is it ereg function? Just can't figure out those patterns and such.. =) Thanks for all help! |
You could look to use
strspn or strcspn rather than using the more 'powerful' (for want of a better term) regular expression functions.PHP Code:
|
There's also the ctype functions to keep in mind for other basic checks. If you wanted a regular expression to do this, it would look something like,
PHP Code:
-m |
Thanks for answering!
@Salathe Those functions were new to me and thanks for pointing them. Unfortunately your example didn't work in my case. ie. If I want to user to do phone number and nothing else. Code:
+358-50-1112233 = passedOtherhand, delayedinsanity your example is what I was looking for!! =) Code:
If there is something else that 1234567890+- then fail!!btw. Does someone know is there some simple instructions how to use those patterns? Thanks. |
well preg_ / ereg_ use the RegEx syntax, i think it is possible to google it, i don't understand it at all myself :P
|
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
Regular Expressions Cheat Sheet - Cheat Sheets - ILoveJackDaniels.com Those are a couple of my favourite's. Google 'regular expressions' to find more... the cheat sheet there is as simple as it gets, though might I suggest if you want to get a good handle on how it's working, you may want to find some example patterns and break them down to learn how they're matching what they're matching and why. Then create some random practice strings of your own and try to match various parts of them. -m |
| All times are GMT. The time now is 05:39 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0