Regex for greater than
Posted: Wed Jan 25, 2012 11:05 pm
I am building a site that will be distributed accross multiple domains. The following code relates to html input fields that may or may not need validation depending on the specific site.
I understand that I can do what I want with just a mathematical greater than in the below code where the <-- REGEX EVALUATION comment is, however I'm trying to make it so that it only has to be edited in the config file.
For this instance of the profileCustom_1 input field I need to test via regex for a value >= 18. So I am needing a regex expression to test that the inputed number is greater than 18..
I understand that I can do what I want with just a mathematical greater than in the below code where the <-- REGEX EVALUATION comment is, however I'm trying to make it so that it only has to be edited in the config file.
For this instance of the profileCustom_1 input field I need to test via regex for a value >= 18. So I am needing a regex expression to test that the inputed number is greater than 18..
Code: Select all
//CONFIG FILE
$config['showProfileCustom_1'] = true;
$config['requireProfileCustom_1'] = true;
$config['validationRegexProfileCustom_1'] = "'^((?!^[0-4])^(\d+))$^'"; // <-- REGEX EXPRESSEION HERE
//FORM PAGE
if ($config['showProfileCustom_1']) { ?>
<div id='profileCustom_1_div'>
<label for="profileCustom_1"><?php
if ($config['requireProfileCustom_1']) { echo "<span class='requiredInputSpan'>* </span>"; }
echo $language['profileCustom_1']; ?></label> <?php
if (!empty($siteRules['profileCustom_1'])) { echo "<div class='regInfo'>".nl2br($siteRules['profileCustom_1'])."</div>"; }
if ($regErrorProfileCustom_1) { ?>
<div id='profileCustom_1_error_div' class='regErrorDiv'> <?php
foreach ($regErrorProfileCustom_1 AS $key => $value){
echo $value."<br>";
}?>
</div><?php
} ?>
<input type="text" name="profileCustom_1" id="profileCustom_1" value="<?php if (!empty($regDetails['profileCustom_1'])) { echo $regDetails['profileCustom_1']; }?>" class="
<?php
if ($regError['profileCustom_1'] == 'true') { echo "inputError"; } else { echo "text3";}
?>" />
</div><?php
}
//FORM PROCESSING PAGE
foreach ($_POST as $K => $V) {
$value = sql_quote(trim($V));
switch($K) {
case "profileCustom_1" :
if ($config['showProfileCustom_1']) {
$i = 0;
$regDetails['profileCustom_1'] = $value;
if ($config['requireProfileCustom_1'] == true && empty($regDetails['profileCustom_1'])) {
$regErrorProfileCustom_1[$i] = $language['profileCustom_1']." is required.";
$i++;
}
else {
if ($config['validationRegexProfileCustom_1'] != "") {
if (!preg_match($config['validationRegexProfileCustom_1'], $regDetails['profileCustom_1'])) { // <-- REGEX EVALUATION
$regErrorProfileCustom_1[$i] = "This value is invalid.";
$i++;
}
else {
$readyForDB[$p]['field'] = "profileCustom_1";
$readyForDB[$p]['value'] = $regDetails['profileCustom_1'];
$p++;
}
}
}
}
break;
}
}