Jump to content


Simple fix needed


5 replies to this topic

#1 evertonian7uk

    Young Padawan

  • Members
  • Pip
  • 249 posts

Posted 26 March 2007 - 03:43 AM

Hi guys,

Whats the tidiest way of saying look, you can only input numbers nothing else:

if($_POST['keyboard']=='enter'){
	if (($trn == "") || (strstr($trn,".")) || (strstr($trn,"a")) ||(strstr($trn,"b")) ||(strstr($trn,"c")) ||(strstr($trn,"d")) ||(strstr($trn,"e")) ||(strstr($trn,"f")) ||(strstr($trn,"g")) ||(strstr($trn,"h")) ||(strstr($trn,"i")) ||(strstr($trn,"j")) ||(strstr($trn,"k")) ||(strstr($trn,"l")) ||(strstr($trn,"m")) ||(strstr($trn,"n")) ||(strstr($trn,"o")) ||(strstr($trn,"p")) ||(strstr($trn,"q")) ||(strstr($trn,"r")) ||(strstr($trn,"s")) ||(strstr($trn,"t")) ||(strstr($trn,"u")) ||(strstr($trn,"v")) ||(strstr($trn,"w")) ||(strstr($trn,"x")) ||(strstr($trn,"y")) ||(strstr($trn,"z")) ||(strstr($trn,"A")) ||(strstr($trn,"B")) ||(strstr($trn,"C")) ||(strstr($trn,"D")) ||(strstr($trn,"E")) ||(strstr($trn,"F")) ||(strstr($trn,"G")) ||(strstr($trn,"H")) ||(strstr($trn,"I")) ||(strstr($trn,"J")) ||(strstr($trn,"K")) ||(strstr($trn,"L")) ||(strstr($trn,"M")) ||(strstr($trn,"N")) ||(strstr($trn,"O")) ||(strstr($trn,"P")) ||(strstr($trn,"Q")) ||(strstr($trn,"R")) ||(strstr($trn,"S")) ||(strstr($trn,"T")) ||(strstr($trn,"U")) ||(strstr($trn,"V")) ||(strstr($trn,"W")) ||(strstr($trn,"X")) ||(strstr($trn,"Y")) ||(strstr($trn,"Z")) ||(strstr($trn,"-")) ||(strstr($trn,"+")) ||(strstr($trn,"!")) ||(strstr($trn,"@"))||(strstr($trn,"#")) ||(strstr($trn,"%"))||(strstr($trn,"^")) ||(strstr($trn,"&"))||(strstr($trn,"*"))||(strstr($trn,"_"))||(strstr($trn,"="))|| (!preg_match ('/^[a-z0-9][a-z0-9\.\-_]*$/i', $trn))){ 
		$error="You don't have enough turns!"; 
	}


is what i have been using, as you can see to much code i know there is an easier line of code to use.

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 26 March 2007 - 05:25 AM

if( preg_match( '¬^[0-9]+$¬', $trn ) ) {
	 #Good: only numbers in the string
} else {
	 #Bad: It can't find a string only consisting of number
}

Simplest way of just checking if an input is numbers or not.

Matt

#3 evertonian7uk

    Young Padawan

  • Members
  • Pip
  • 249 posts

Posted 27 March 2007 - 04:33 AM

Mr.Matt

thanks a mill for your help, i have been struggling to add your code to my file tho for some reason:

how would you put the above into this:


Resolved

thanks to Mr.Matt

Edited by evertonian7uk, 27 March 2007 - 08:36 AM.


#4 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 27 March 2007 - 08:07 AM

<?
include("html.php");

$pmp = mysql_fetch_array(mysql_query("SELECT trn,whore,thug,weed,condom,crack,medicine,thappy,whappy,money,informer,defturns1

,areset FROM $tab[pimp] WHERE id='$id';"));

$status = mysql_fetch_array(mysql_query("SELECT status FROM users WHERE id='$id1';"));


if($_POST['keyboard']=='enter'){
	if( !preg_match( '¬^[0-9]+$¬', $trn ) ) {
		$error="You don't have enough turns!";
	} else if( $trn <= 5 ) {
		$error="You must use more than 5 turns pimp!";
	} else {
		srand ((double) microtime() * 1000000);
	}


#5 evertonian7uk

    Young Padawan

  • Members
  • Pip
  • 249 posts

Posted 27 March 2007 - 08:35 AM

Thanks so much for the help there buddy!

worked a charm!!

if would rep you if i could but i dont see the option here!

again, thanks a mill :D

#6 SecondV

    Young Padawan

  • Members
  • Pip
  • 28 posts
  • Gender:Male
  • Location:Kentucky
  • Interests:All things PHP &amp; MySQL :)

Posted 27 March 2007 - 06:23 PM

www.php.net/is_int

www.php.net/is_numeric





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users