daddywifi Posted August 31, 2006 Share Posted August 31, 2006 I am still new to PHP and I am trying to create a page to evaluate a form field for the following things:1. Not be empty, which I have successfully completed2. To be a certain length, which I have also sucessfully completed3. That the first 5 characters be 1 of 2 different valuesCan anyone help me? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/19292-evaluate-a-string/ Share on other sites More sharing options...
Orio Posted August 31, 2006 Share Posted August 31, 2006 What do you mean by "1 of 2 diffrent values"? For example- they can be only "A" or "B"?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/19292-evaluate-a-string/#findComment-83677 Share on other sites More sharing options...
HuggieBear Posted August 31, 2006 Share Posted August 31, 2006 You could use a regular expression:[code]if (preg_match("/^(12345|54321)/", $_GET['field_name'])){ //do something here}else { // ...}[/code]Should do it.In fact you could use a RegEx for the whole thing. Lets say your field has to have 9 characters, not be null and start with either 'email' or 'phone'[code]if (preg_match("/^(email|phone)\w{4}/", $_GET['field_name'])){ // It's fine...}else { // show me an error...}[/code]RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/19292-evaluate-a-string/#findComment-83680 Share on other sites More sharing options...
daddywifi Posted September 1, 2006 Author Share Posted September 1, 2006 Orio,Yes an "A" or "B" value. Also thanks HuggieBear, but I am unsure what all of the items in the expressions you provided mean :(Here is a better ex of what I am doing:I have some users that are identified by a unique 14 digit#, but the first 5 digits of the number meet 2 different values either value "A" or value "B". I provide a subscription service that they can access from home, but want to verify that they are my users before allowing access to the service. In doing this I need to be sure they dont enter a null value, that the value entered is 14 digits, and that it matches either value "A" or value "B". I had this created to evaluate the form field, but it returns false each time:if (empty($id) || strlen($id) != 14 || substr($id,0,5) != '12345' || substr($id,0,5) != '09876')Thanks again for the help Quote Link to comment https://forums.phpfreaks.com/topic/19292-evaluate-a-string/#findComment-84149 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.