Mrwilson1 Posted May 16, 2007 Share Posted May 16, 2007 I am trying to validate the following in which the requirement for validation is 3 letters (months) and 1 digit. What is the proper format? include(isset($_GET['page']) && preg_match('/^\w(3)\d+\.htm$/', $_GET['page']) ? $_GET['page'] : 'apr7.htm'); all file names will appear as the expression "apr7.htm above thanks Quote Link to comment Share on other sites More sharing options...
effigy Posted May 16, 2007 Share Posted May 16, 2007 Below is a very specific example. Your pattern is not working because (3) should be {3} to quantify the \w. And remember that \w includes digits and an underscore. Also, shouldn't you be checking for the file's existence? <?php include( (isset($_GET['page']) && preg_match('/^(?:jan|feb|ma[ry]|apr|ju[nl]|aug|sep|oct|nov|dec)\d+\.htm\z/', $_GET['page'])) ? $_GET['page'] : 'apr7.htm' ); ?> Quote Link to comment Share on other sites More sharing options...
Mrwilson1 Posted May 16, 2007 Author Share Posted May 16, 2007 I think checking for the file existance would be appropriate. But what would I use if I just want to check for a certain number of letters? In the example you give the file names certainly work in this case, but looking on to other form fields and other files, would ('/^/w{3}\.htm\z' work to just validate that the file name is of a certain amount of letters/numbers? I guess I am asking if I can use \w{3} as the pattern to match without adding more names such as in your example (thanks BTW) Can you also show me how to check for file existence? I am assuming that would be an "if (file_exists" statement between this: htm\z/', $_GET['page'? Quote Link to comment Share on other sites More sharing options...
effigy Posted May 16, 2007 Share Posted May 16, 2007 \w{3} is the equivalent of [a-zA-Z0-9_]{3}, which will only match exactly 3 instances of anything within the square braces. Yes, use file_exists. Quote Link to comment Share on other sites More sharing options...
Mrwilson1 Posted May 17, 2007 Author Share Posted May 17, 2007 Thank you for your patience and help, you are appreciated Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.