0

Good afternoon everyone.
I need to write out a simple validation. It needs to validate only if a user enters certain keywords.
Here what I have so far:

if(!preg_match("Indiana, Ohio", $state)) { 
    $errors .= "You have entered the wrong state."; 
}

What would be the correct preg_match function to only validate for Indiana and Ohio?

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by double_cola
0

@double_cola

What would be the correct preg_match function to only validate for Indiana and Ohio?

You can used the Zip code or State Abbreviations.

I think it's best to used the State Abbreviations because the Zip code will be a lot of numbers. But for Abbreviations it's just 2 letters!

IN - Indiana
OH - Ohio
0

I would do it simple way without regular expressions which are not very efficient:

$allowed = array('Indiana', 'Ohio');

if(!in_array(allowed)) {
    $errors .= "You have entered the wrong state."; 
}

Edited by broj1

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.