Check if “is digits” and does not begin with zero
Protecting Your PHP/SQL Queries from SQL Injection is one of coding obligations, if you have tables with AUTO_INCREMENT and you want to check IDs before running queries, this function is yours.
function is_digits($string){
return preg_match("!^[1-9]([0-9]+)?$!",$string);
}
Examples :
is_digits(0); // Return 0
is_digits(1); // Return 1
is_digits("1"); // Return 1
is_digits(01); // Return 0
is_digits(-1); // Return 0
is_digits("1a"); // Return 0
is_digits("a1"); // Return 0
is_digits(15); // Return 1
is_digits(1,5); // Return 0
is_digits(1.5); // Return 0
September 25th, 2009 in
Development, Tricks | tags: AUTO_INCREMENT, is_digits(), is_numeric(), MySql, php, Protecting mysql Injection, Validating digits
Nice article ; Keep on bro