Question : PHP String Contains exactly one number and one letter

i want to be able to determine that a string has only 1 letter and 1 number in it and nothing else.
That the string is 2 characters in length and one is a letter and one is a number.

Thanks.

Answer : PHP String Contains exactly one number and one letter

This regex should do it - see sample code below
1:
2:
3:
4:
5:
6:
7:
8:
9:
<?php

$testArray = array( "ahsaj", "272727", "aa", "11", "a1", "aa", "1a", "11" );

$pattern = '~^([0-9]{1}[a-zA-Z]{1}|[a-zA-Z{1}][0-9]{1})$~';

foreach( $testArray as $aTest )
     if ( preg_match( $pattern, $aTest ) > 0 )
          echo "$aTest is OK<br/>";
Random Solutions  
 
programming4us programming4us