I'm trying to validate a form input object of type text using regular expressions.
I would like to allow any number or combination of letters, numbers, and/or the characters "_","-", "&".
Anything else I'd like to have recognized as invalid.
Any ideas of how to do this with regular expressions in php?
Thanks!
Regular Expressions question
Moderator: General Moderators
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Re: Regular Expressions question
This should do the trick:latinomigs wrote:I'm trying to validate a form input object of type text using regular expressions.
I would like to allow any number or combination of letters, numbers, and/or the characters "_","-", "&".
Anything else I'd like to have recognized as invalid.
Any ideas of how to do this with regular expressions in php?
Thanks!
Code: Select all
<?php
$string = "test01_-:abc/1&";
if(!eregi("^([a-zA-Z0-9\&_\-]*)$", $string )) {
echo "invalid!";
}
else{
echo "success";
}
?>