| | |
regular expression
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
so I am trying to write a regular expression lets just take this case for an example: OR an empty string, how would I add that part?
I tried stuff like: but to no avail, any ideas?
PHP Syntax (Toggle Plain Text)
^[0-9a-z]{5,9}$
I tried stuff like:
PHP Syntax (Toggle Plain Text)
^([0-9a-z]{5,9}|[]{0})$
My suggestion would be to avoid putting so much overhead in the regular expression engine for such a simple test. You can accomplish what you want in PHP by doing something like:
[PHP]
# Assuming you are testing $string...
if(preg_match('/^[0-9a-z]{5,9}$/',$string) || strlen($string) < 1) {
# Do things here.
}
[/PHP]
How about that?
[PHP]
# Assuming you are testing $string...
if(preg_match('/^[0-9a-z]{5,9}$/',$string) || strlen($string) < 1) {
# Do things here.
}
[/PHP]
How about that?
![]() |
Similar Threads
- Regular Expression (Perl)
- How to write javascript regular expression for this case? (JSP)
- Regular Expression Matching New Line (Perl)
- Regular expression (Perl)
- Looking for table rows with Regular expression. (PHP)
Other Threads in the PHP Forum
- Previous Thread: Is it possible to pass hidden value in <select> drop down menu?
- Next Thread: Reading file names from a folder
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date development directory display download dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parse parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql structure syntax system table thesishelp tutorial update upload url validation validator variable video web xml youtube





