| The Arcive of vBulletin Modifications Site. | |
| 
			 
			#1  
			
			
			
			
			
		 | ||||
| 
 | ||||
|  How do you check for more than 1 letter for a variable? 
			
			How do you check to make sure that a variable only allows 1 letter or number? Here is the variable I am using in the php file: Code: $vbulletin->GPC['letter'] I want to do a check to make sure only one letter or number is entered. Right now you can enter anything for it. | 
| 
			 
			#2  
			
			
			
			
			
		 | |||
| 
 | |||
|   Quote: 
 PHP Code: 
			 | 
| 
			 
			#3  
			
			
			
			
			
		 | ||||
| 
 | ||||
|   
			
			You are the man! Thank you! I was way off on the regex as I suck at those. Here is what I ended up using: Code: 	if (!(strlen($vbulletin->GPC['letter']) == 1) && preg_match('/^[a-zA-Z0-9]+$/', $vbulletin->GPC['letter']))
	{
		print_stop_message('cannot_have_null_values');
	}I will be using a different stop message, but I wanted to make sure I could get it to work first. I have another condition before this one that checks to make sure all 3 variables (letter + 2 others) are not blank. I was going to add this to that but I wanted to catch the letter variable separately. This is how it all looks together for the error checking: Code: 	if (!$vbulletin->GPC['quote'] OR !$vbulletin->GPC['name'] OR !$vbulletin->GPC['letter'])
	{
		print_stop_message('cannot_have_null_values');
	}
	if (!(strlen($vbulletin->GPC['letter']) == 1) && preg_match('/^[a-zA-Z0-9]+$/', $vbulletin->GPC['letter']))
	{
		print_stop_message('cannot_have_null_values');
	}If you have any suggestion s or advice, I am all ears. And thank you again.   | 
| 
			 
			#4  
			
			
			
			
			
		 | |||
| 
 | |||
|   
			
			If you are going to split it up and give messages I'd do something like this and split it a bit more, otherwise the user might get confused with one message for multiple conditions. PHP Code: 
			 | 
| 
			 
			#5  
			
			
			
			
			
		 | ||||
| 
 | ||||
|   
			
			Couldn't you do elseif's there also?
		 | 
| 
			 
			#6  
			
			
			
			
			
		 | |||
| 
 | |||
|   
			
			You could use an elseif if you want. I normally would do it differently. I would usually add the errors to a variable then output the variable, that way all the errors are shown at once instead of the user having to submit 3 times before he see's all the errors.
		 | 
| 
			 
			#7  
			
			
			
			
			
		 | ||||
| 
 | ||||
|   
			
			I've never done it with a variable like that. Can you give me an example how I could do that?
		 | 
| 
			 
			#8  
			
			
			
			
			
		 | ||||
| 
 | ||||
|   
			
			Something like this should suffice. PHP Code: 
			  | 
| 
			 
			#9  
			
			
			
			
			
		 | ||||
| 
 | ||||
|   
			
			Thanks. I'll play with that and see what I can come up with.
		 | 
|  | 
| 
 | 
 | 
| X vBulletin 3.8.12 by vBS Debug Information | |
|---|---|
| 
 | |
|  More Information | |
| Template Usage: 
 Phrase Groups Available: 
 | Included Files: 
 Hooks Called: 
 |