| | |
Simple PHP Regex Question!
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2007
Posts: 64
Reputation:
Solved Threads: 0
Hi! I have a question that probably has a really simple answer
. I have a regex that validates names:
Only if the name I enter has an apostrophe, it gives me my error message. Can someone please help me modify this regex so that it will allow a name like "O'Sullivan" or "Smith-Jacobs" to be entered? Thanks a ton!
. I have a regex that validates names: PHP Syntax (Toggle Plain Text)
elseif (!preg_match('#^[a-z0-9\' -]{1,35}$#i',$lastname )) { include('includes/error.php'); }
Only if the name I enter has an apostrophe, it gives me my error message. Can someone please help me modify this regex so that it will allow a name like "O'Sullivan" or "Smith-Jacobs" to be entered? Thanks a ton!
Strange, I tested it and it works fine for me. O'Reilly matches, Smith matches, Smith-Jacobs matches. The only thing that doesn't match is stuff like @#$%@#
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Aug 2007
Posts: 64
Reputation:
Solved Threads: 0
Thanks for the reply. I've tried it on two browsers now and can't get "O'Sullivan" to validate, while "Smith-Jacobs" does just fine!
Here's what I'm using:
Please help
. Much thanks!
Here's what I'm using:
PHP Syntax (Toggle Plain Text)
<form action="" method="post"> <input type="text" name="text"> <input type="submit" name="submit"> </form> <?php if (isset($_POST['submit'])) { $text = $_POST['text']; if (!preg_match('#^[a-z0-9\' -]{1,35}$#i',$text )) { echo "fail"; } else { echo "success"; } } ?>
Please help
. Much thanks! The place to start debugging is by echoing the variable to see if it is what you think it is. You may have magicquotes turned on and O'Reilly is actually O\'Reilly
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Aug 2007
Posts: 64
Reputation:
Solved Threads: 0
Thank you! And if it's echoing with an escaped apostrophe, how can I go about stopping that for validation? I made a work-around:
But that one line would be a significant modification to a large-portion of code. Is there an easy way to go about this? Thanks again!
PHP Syntax (Toggle Plain Text)
<form action="" method="post"> <input type="text" name="text"> <input type="submit" name="submit"> </form> <?php if (isset($_POST['submit'])) { $text = $_POST['text']; $text = str_replace("\\","",$text); if (!preg_match('#^[a-z0-9\' -]{1,35}$#i',$text )) { echo "fail"; } else { echo "success"; } } ?>
But that one line would be a significant modification to a large-portion of code. Is there an easy way to go about this? Thanks again!
Well you could turn magic quotes off http://php.net/magicquotes or you can use the stripslashes function
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
![]() |
Similar Threads
- Simple PHP Cart (PHP)
- simple php script fix (PHP)
- Can I get a simple php code to measure how many words per minute someone can type? (PHP)
- php regex for form validation (PHP)
- Simple PHP Question (PHP)
- generating txt using php (PHP)
- question about connecting odbc to sql through php script (PHP)
Other Threads in the PHP Forum
- Previous Thread: How to view a word file as html?
- Next Thread: Users have to login and logout twice, why?
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube







