| | |
preg_match validation
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2009
Posts: 12
Reputation:
Solved Threads: 1
Hi,
I have a piece of code below:
This should check if $new_pagealias & $new_pagekeywords contain invalid characters, other than a-bA-B0-9 etc which works fine.
Well. The first one which checks the page alias works fine. The second one to check the keywords, doesn't. If I post a var to it containing the string '@' it will go through it and enter it into the database, same goes for the string "holiday, sunshine, ' " My HTML page will echo the meta etc ending with: holiday, sunshine, ' '/>
This ends the tag early which will error some browsers, plus I just want it to be perfect and not have to echo invalid keywords.
Plus I need the preg_match for $new_pagekeywords to validate and allow commas.
At the moment if I put the string "My house!" through alias & keywords, it will error for alias, but if I change alias to "house' and leave keywords as "My house!" it won't define $error & stop the SQL input.
Help?
Thanks in advance,
Josh
I have a piece of code below:
php Syntax (Toggle Plain Text)
// Check our data if (preg_match('/[^a-zA-Z0-9]/', $new_pagealias)) $error = "Invalid page alias. Use only normal characters."; if (preg_match('/[^a-zA-Z0-9]/', $new_pagekeywords)) $error = "Invalid page keywords. Use only normal characters."; if (!$new_pagealias) $error = "Page alias is missing"; if (!$new_pagename) $error = "Page name is missing"; if (!$new_pagetitle) $error = "Page title is missing";
This should check if $new_pagealias & $new_pagekeywords contain invalid characters, other than a-bA-B0-9 etc which works fine.
Well. The first one which checks the page alias works fine. The second one to check the keywords, doesn't. If I post a var to it containing the string '@' it will go through it and enter it into the database, same goes for the string "holiday, sunshine, ' " My HTML page will echo the meta etc ending with: holiday, sunshine, ' '/>
This ends the tag early which will error some browsers, plus I just want it to be perfect and not have to echo invalid keywords.
Plus I need the preg_match for $new_pagekeywords to validate and allow commas.
At the moment if I put the string "My house!" through alias & keywords, it will error for alias, but if I change alias to "house' and leave keywords as "My house!" it won't define $error & stop the SQL input.
Help?

Thanks in advance,
Josh
1
#2 Oct 30th, 2009
If you want to use preg functions, then this should work to match strings containing alphanumeric characters and spaces:
PHP Syntax (Toggle Plain Text)
$pattern = '#^[a-z0-9\x20]+$#i'; if (preg_match($pattern, $new_pagealias)) $error = "Invalid page alias. Use only normal characters.";
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
![]() |
Other Threads in the PHP Forum
- Previous Thread: How earn through online PHP project?????
- Next Thread: Please Help Me Fix My PHP Register Form
Views: 316 | Replies: 3
| 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 directory display download duplicates dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link links login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php phpvotingscript problem query radio random recursion regex remote script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





