View Full Version : preg_match
Dennis_Gull
07-29-2007, 10:07 PM
Hello, im trying to get preg_match to check if two characters exist in my input field but im not quite sure how it works. This is what I got
if(preg_match('/.@/' , $_POST['variable'])) {...
This will be true if i have either . or @ but I wanna check if the post have them both, does anyone know how to do this?
djr33
07-30-2007, 01:17 AM
Do it twice, once for each character.
In fact, just use strpos() instead.
Dennis_Gull
07-30-2007, 01:26 AM
okay, guess i do that then :)
/.@/This will match if you have an ampersand preceded by any character. I think you meant:
/[\.@]/which would match if you had a dot or an @ symbol in the code. You could say:
/@.+?\./ - an @ symbol, some characters, and then a dot.
djr33
07-30-2007, 04:11 AM
But if you wanted . then @ OR @ then ., you would still need two statements.
boxxertrumps
07-30-2007, 09:25 AM
No. (@.*\.|\..+@)
EDIT:
( begins or statement
| separates choices
) ends or statement
Dennis_Gull
07-30-2007, 02:32 PM
I haven't tried the code yet (i use two statements for now) but could someone tell me what all the characters do?
@ and / = start and end?
| separates?
\ * . + does?
mburt
07-30-2007, 02:38 PM
Statements in a regular expression execute in the order they come. Brackets () are just a way of grouping a certain expression, the | character is simply a way of creating another statement within the same expression.
$found = strpos(".") && strpos("&") ? true : false;
(@.*\.|\..+@)Oh yes, I forgot about that.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.