Jump to content

[SOLVED] Easiest Way to check string is Alpha-Numeric


ChadNomad

Recommended Posts

 

Here a eregi version


<?php

$word="hi there i am redarrow i am 34";

$result=explode(' ',$word);

foreach($result as $x){

if(eregi("^[a-z]{0,100}$",$x)){

echo " <br> $x was alphanumeric <br>";

}else{

echo" <br> sorry $x word was not alphanumeric";

}
}
?>

 

 

 

 

Here a eregi version


<?php
if(eregi("^[a-z]{0,100}$",$x)){

The only issue is that a-z doesn't allow capital letters, and (I think) the {0, 100} is the amount of text that can be sent through...

try:

if(eregi("^[a-zA-Z0-9]$", $x)) {

 

Or the easier way:

 

if(preg_match('^[[:alnum:]]$', $x) {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.