n3ightjay Posted November 4, 2008 Share Posted November 4, 2008 Hey Guys ... never used regex and don't really get it (yet fingers crossed) but i need to check a string meets a length and prefix expression. i need the string to match: "SNPLXXXXX" where the "X"'s are integers and "SNPL" is the manditory prefix what i know is (is not much): if (eregi("", $_POST['barCode'])){ Link to comment https://forums.phpfreaks.com/topic/131354-solved-regex-request/ Share on other sites More sharing options...
sasa Posted November 4, 2008 Share Posted November 4, 2008 try <?php $string = trim($_POST['barCode']); //$string = 'SNPL12345'; echo preg_match('/^SNPL[0-9]{5,5}$/',$string) ? 'true' : 'false'; ?> Link to comment https://forums.phpfreaks.com/topic/131354-solved-regex-request/#findComment-682148 Share on other sites More sharing options...
nrg_alpha Posted November 4, 2008 Share Posted November 4, 2008 Sasa, when you need 5 digits, you don't need to state an equal minimum and a maximum.. simply use {5}. To the OP, try to learn preg (part of Perl Compatible Regular Expressions) instead of ereg. As of PHP6, POSIX (which ereg is part of) will not be supported within the PHP6 core by default. I believe it will only be available as an extension. There are resources here at PHPFreaks to help you out with that. Cheers, NRG Link to comment https://forums.phpfreaks.com/topic/131354-solved-regex-request/#findComment-682171 Share on other sites More sharing options...
n3ightjay Posted November 4, 2008 Author Share Posted November 4, 2008 Thanks sasa thanks for the direction and resources NRG Neight Link to comment https://forums.phpfreaks.com/topic/131354-solved-regex-request/#findComment-682174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.