ehigginsfreese Posted January 15, 2009 Share Posted January 15, 2009 I need to create a really simple page where we validate a number entered by a user. They enter their library card number if it is 13 characters long and starts with "10001" then they get directed to a web page, if not they get dumped back to the data entry page with a message that they need to enter a valid library card number. We don't need to check that it is actually a real library card number - just that it is 13 characters and starts with "10001" So this seems pretty simple, but I am very, very new to PHP and I would love some help. I think I need to use the strlen function to check that it is 13 characters so something like "$libIDLength = strlen($libID)" Then I could say if $libIDLength == 13 redirect, if not error. I am not sure how to get the first 5 characters and check to see if they are "10001" though. I am also not sure how to do a two condition If statement. The data needs to be both 13 character and start with "10001" but all the If/else examples I have seen just have one condition for each else. Can someone help me sort this out a bit? Thank you so much for any help Link to comment https://forums.phpfreaks.com/topic/140975-newbie-validation-help-simple-number-validation/ Share on other sites More sharing options...
Zhadus Posted January 15, 2009 Share Posted January 15, 2009 if (strpos($libID, '10001') === 0) { good } else { redirect } Checks to make sure 10001 occurs at the beginning of the string. Link to comment https://forums.phpfreaks.com/topic/140975-newbie-validation-help-simple-number-validation/#findComment-737861 Share on other sites More sharing options...
ehigginsfreese Posted January 15, 2009 Author Share Posted January 15, 2009 Thanks. I will try that out ASAP Link to comment https://forums.phpfreaks.com/topic/140975-newbie-validation-help-simple-number-validation/#findComment-737865 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.