How can i check to see if a php string contains only 0-9 , and |? so it would accept 158,147|157,541|145,157 but not 125 ,148|126,4
How can i check to see if a php string contains only 0-9 ,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use regex:
The regex explained:
~is just the regex delimiter^is the start of string anchor[...]is a character class\dis a shorthand that means any character in the0-9range|and,are just the|and,literals.+is the “one or more” repetition operator$is the end of string anchorIt basically means:
Match a string that only has the following characters:
0-9,,and|.Change it to:
If you don’t want it to reject the empty string. The
*means “zero or more” (instead of+, which is “one or more”)Regex Reference: http://regular-expressions.info/