![]() |
RegEx to change format of input
I'm using
Code:
$cleangc = preg_replace("/[^a-zA-Z0-9\s]/", "", $gamecode);For example slus_123.45 would output as SLUS-12345 |
PHP Code:
|
That works well if slus_123.45 was the only acceptable format.. but if the user enters any other format nothing is inserted.
I need the format of anything entered to change, basically.. So if slus-12345 is entered, it stays the same. If slus12345 is entered, it's changed to slus-12345... if slus_123.45 is entered, it changes to slus-12345.. I feel like this can be accomplished somehow with the simple code that I am already using. Here is my current method to just replace everything with "" Code:
if(isset($_POST['gamecode'])) {Code:
$cleangc = preg_replace("/([^a-zA-Z]) ([0-9\s])/", "$1-$2", $gamecode);Any tip appreciated! |
This works for all the variants you gave.
and also "coding forums_245.54.3" PHP Code:
|
Quote:
|
| All times are GMT +1. The time now is 07:25 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.