SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Perl Regex not working
-
Sep 19, 2009, 03:47 #1
- Join Date
- Jul 2008
- Location
- Somerset, England
- Posts
- 459
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Perl Regex not working
I am looking to capture the users firstname, and I only want to capture characters so im using the preg_match function. The problem is with the code below, im not getting a match when typing in a simple name such as "john".
//Clean user input
$inString = $_POST['alias'];
$cleanAlias = clean_input($inString) ."<br />";
//Peform Form Validation!
$pattern = '/^[A-Za-z]$/';
$subject = $cleanAlias;
if(preg_match($pattern, $subject))
{
echo "match found";
}
else
{
echo "no match found";
}
-
Sep 19, 2009, 04:16 #2
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
What you're asking for by using:
Code:/^[A-Za-z]$/
If you want multiple letters:
Code:/^[A-Za-z]*$/
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Sep 19, 2009, 04:20 #3
- Join Date
- Jul 2008
- Location
- Somerset, England
- Posts
- 459
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi, thanks for your reply! ive tried your version, but still not match
-
Sep 21, 2009, 07:56 #4
Given the code in your first post, the $subject variable will contain the string john<br /> (assuming the cleaning function returns john) which clearly contains characters not in the alphabet.
Bookmarks