summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page3
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page21
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page74
-rw-r--r--demos/quickstart/protected/pages/Controls/Validation.page39
-rw-r--r--framework/Exceptions/messages.txt6
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php4
-rw-r--r--framework/Web/UI/WebControls/TCompareValidator.php2
-rw-r--r--framework/Web/UI/WebControls/TEmailAddressValidator.php24
-rw-r--r--framework/Web/UI/WebControls/TRegularExpressionValidator.php1
-rw-r--r--framework/Web/UI/WebControls/TValueTypeValidator.php21
10 files changed, 156 insertions, 39 deletions
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page
index db63a0a9..79066e44 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page
@@ -1,7 +1,7 @@
<com:TContent ID="body">
<h1>TEmailAddressValidator Samples</h1>
-<p><strong>Note:</strong>TEmailAddressValidator will start
+<p><strong>Note:</strong> TEmailAddressValidator will start
to validate only if the input is not empty.</p>
<table class="sampletable">
@@ -44,6 +44,7 @@ Email address validator with focus-on-error enabled and dynamic display:
<com:TEmailAddressValidator
ValidationGroup="Group3"
ControlToValidate="TextBox3"
+ FocusOnError="true"
Display="Dynamic"
Text="Invalid email address." />
<com:TButton Text="Submit" ValidationGroup="Group3" />
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page
index 5ce43fda..9c27057b 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.page
@@ -1,8 +1,11 @@
<com:TContent ID="body">
<h1>TRegularExpressionValidator Samples</h1>
-<p><strong>Note:</strong>TRegularExpressionValidator will start
-to validate only if the input is not empty.</p>
+<p>
+<strong>Note:</strong> TRegularExpressionValidator will start
+to validate only if the input is not empty.
+</p>
+
<table class="sampletable">
<tr>
@@ -10,12 +13,12 @@ to validate only if the input is not empty.</p>
Regular expression validator with default settings:
</td>
<td class="sampleaction">
-<com:TTextBox ID="TextBox1" Text="a"/>
+<com:TTextBox ID="TextBox1" Text="xxx-xx-xxxx"/>
<com:TRegularExpressionValidator
ValidationGroup="Group1"
ControlToValidate="TextBox1"
- RegularExpression="\d+"
- Text="Only digits are allowed." />
+ RegularExpression="\d{3}-\d{2}-\d{4}"
+ Text="SSN must be in the format of xxx-xx-xxxx." />
<com:TButton Text="Submit" ValidationGroup="Group1" />
</td>
</tr>
@@ -30,8 +33,8 @@ Regular expression validator with client-side validation disabled:
ValidationGroup="Group2"
EnableClientScript="false"
ControlToValidate="TextBox2"
- RegularExpression="\d+"
- Text="Only digits are allowed." />
+ RegularExpression="[\w]{6,}"
+ Text="Input must consist of at least 6 characters." />
<com:TButton Text="Submit" ValidationGroup="Group2" />
</td>
</tr>
@@ -46,8 +49,8 @@ Regular expression validator with focus-on-error enabled and dynamic display:
ValidationGroup="Group3"
ControlToValidate="TextBox3"
Display="Dynamic"
- RegularExpression="\d+"
- Text="Only digits are allowed." />
+ RegularExpression="\d{5}(-\d{4})?"
+ Text="Invalid US ZIP code." />
<com:TButton Text="Submit" ValidationGroup="Group3" />
</td>
</tr>
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page
index 36d02ced..e5c27cd0 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.page
@@ -6,7 +6,7 @@
<tr>
<td class="samplenote">
-Required field validator with default settings:
+Validator with default settings:
</td>
<td class="sampleaction">
<com:TTextBox ID="TextBox1" />
@@ -20,7 +20,7 @@ Required field validator with default settings:
<tr>
<td class="samplenote">
-Required field validator with client-side validation disabled:
+Validator with client-side validation disabled:
</td>
<td class="sampleaction">
<com:TTextBox ID="TextBox2" />
@@ -35,12 +35,13 @@ Required field validator with client-side validation disabled:
<tr>
<td class="samplenote">
-Required field validator with focus-on-error enabled and dynamic display:
+Validator with focus-on-error enabled and dynamic display:
</td>
<td class="sampleaction">
<com:TTextBox ID="TextBox3" />
<com:TRequiredFieldValidator
ValidationGroup="Group3"
+ Display="Dynamic"
ControlToValidate="TextBox3"
FocusOnError="true"
Text="Field required." />
@@ -48,6 +49,73 @@ Required field validator with focus-on-error enabled and dynamic display:
</td>
</tr>
+<tr>
+<td class="samplenote">
+Validating if initial value (test) is changed:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox4" Text="test" />
+<com:TRequiredFieldValidator
+ ValidationGroup="Group4"
+ Display="Dynamic"
+ ControlToValidate="TextBox4"
+ InitialValue="test"
+ Text="Input must not be 'test'." />
+<com:TButton Text="Submit" ValidationGroup="Group4" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Validating if checkbox is checked:
+</td>
+<td class="sampleaction">
+<com:TCheckBox ID="CheckBox" Text="agree" />
+<com:TRequiredFieldValidator
+ ValidationGroup="Group5"
+ Display="Dynamic"
+ ControlToValidate="CheckBox"
+ Text="You must agree." />
+<com:TButton Text="Submit" ValidationGroup="Group5" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Validating if a selection has been made in a dropdown list:
+</td>
+<td class="sampleaction">
+<com:TDropDownList ID="DropDownList">
+ <com:TListItem Value="value 1" Text="text 1" Selected="true" />
+ <com:TListItem Value="value 2" Text="text 2" />
+ <com:TListItem Value="value 3" Text="text 3" />
+</com:TDropDownList>
+<com:TRequiredFieldValidator
+ ValidationGroup="Group6"
+ ControlToValidate="DropDownList"
+ InitialValue="value 1"
+ Text="A selection must be made." />
+<com:TButton Text="Submit" ValidationGroup="Group6" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Validating if a selection has been made in a dropdown list:
+</td>
+<td class="sampleaction">
+<com:TListBox ID="ListBox">
+ <com:TListItem Value="value 1" Text="text 1" />
+ <com:TListItem Value="value 2" Text="text 2" />
+ <com:TListItem Value="value 3" Text="text 3" />
+</com:TListBox>
+<com:TRequiredFieldValidator
+ ValidationGroup="Group7"
+ ControlToValidate="ListBox"
+ Text="A selection must be made." />
+<com:TButton Text="Submit" ValidationGroup="Group7" />
+</td>
+</tr>
</table>
diff --git a/demos/quickstart/protected/pages/Controls/Validation.page b/demos/quickstart/protected/pages/Controls/Validation.page
index 74925447..fe801183 100644
--- a/demos/quickstart/protected/pages/Controls/Validation.page
+++ b/demos/quickstart/protected/pages/Controls/Validation.page
@@ -12,7 +12,7 @@ In addition, if <tt>EnableClientScript</tt> is true, validation will also be per
<dl>
<dt>ControlToValidate</dt>
<dd>The <tt>ID</tt> of the component for this validator. This property must be set to the <tt>ID</tt> path of an input component. The <tt>ID</tt> path is the dot-connected IDs of the components reaching from the validator's parent component to the target component. </dd>
-
+
<dt>ErrorMessage</dt>
<dd>The text for the error message when the input component failed to validate.</dd>
@@ -21,14 +21,14 @@ In addition, if <tt>EnableClientScript</tt> is true, validation will also be per
</dd>
<dt>Display</dt>
- <dd>The display behavior of the error message in a validation component. The allowed values are: <tt>None</tt>, <tt>Static</tt> and <tt>Dynamic</tt>. The default is <tt>Static</tt>.
+ <dd>The display behavior of the error message in a validation component. The allowed values are: <tt>None</tt>, <tt>Static</tt> and <tt>Dynamic</tt>. The default is <tt>Static</tt>.
<ul>
<li><tt>None</tt> -- the validator component and the error message will not be displayed. </li>
<li><tt>Dynamic</tt> -- CSS for the error is constructed in such a way that space for the error message on the page is NOT reserved. When the user hits the "submit" button, applicable error messages will show up shifting the layout of your page around (usually down). </li>
<li><tt>Static</tt> -- CSS for the error is constructed in such a way that space for the error message on the page is always reserved. When the user hits the "submit" button, applicable error messages will just show up, not altering the layout of your page. </li>
</ul>
</dd>
-
+
<dt>EnableClientScript</dt>
<dd>Indicating whether client-side validation is enabled. Default is true.</dd>
</dl>
@@ -53,7 +53,6 @@ This is the simplest validator, ensuring that the input field has some sort of v
<dd>The regular expression that determines the pattern used to validate a field. Some commonly used regular expressions include:
<ul>
<li>At least 6 characters: <code>[\w]{6,}</code></li>
- <li>Internal URL: <code>http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)? </code></li>
<li>Japanese Phone Number: <code>(0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}</code></li>
<li>Japanese Postal Code: <code>\d{3}(-(\d{4}|\d{2}))?</code></li>
<li>P.R.C. Phone Number: <code>(\(\d{3}\)|\d{3}-)?\d{8} </code></li>
@@ -63,15 +62,21 @@ This is the simplest validator, ensuring that the input field has some sort of v
<li>U.S. ZIP Code: <code>\d{5}(-\d{4})?</code></li>
<li>U.S. Social Security Number: <code>\d{3}-\d{2}-\d{4}</code></li>
</ul>
- More regular expression patterns can be found on the Internet, e.g.
+ More regular expression patterns can be found on the Internet, e.g.
<a href="http://regexlib.com/">http://regexlib.com/</a>.
</dd>
</dl>
+<p>
+Note, if the value being validated is empty, TRegularExpressionValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty.
+</p>
<com:RunBar PagePath="Controls.Samples.TRegularExpressionValidator.Home" />
<h2>TEmailAddressValidator</h2>
-<p><tt>TEmailAddressValidator</tt> validates whether the value of an associated input component is a valid email address. It will check MX record if <tt>checkdnsrr()</tt> is available in the installed PHP.
+<p><tt>TEmailAddressValidator</tt> validates whether the value of an associated input component is a valid email address. If <tt>CheckMXRecord</tt> is true, besides checking the format of the input value, the validator will also check MX record for the email address, provided <tt>checkdnsrr()</tt> is available in the installed PHP.
+</p>
+<p>
+Note, if the value being validated is empty, TEmailAddressValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty.
</p>
<com:RunBar PagePath="Controls.Samples.TEmailAddressValidator.Home" />
@@ -81,10 +86,10 @@ This is the simplest validator, ensuring that the input field has some sort of v
<dl>
<dt>ControlToCompare</dt>
<dd>The input component to compare with the input control being validated. </dd>
-
+
<dt>ValueToCompare</dt>
<dd>A constant value to compare with the value entered by the user into the input component being validated. </dd>
-
+
<dt>ValueType</dt>
<dd>The data type (<tt>Integer</tt>, <tt>Double</tt>, <tt>Currency</tt>, <tt>Date</tt>, <tt>String</tt>) that the values being compared are converted to before the comparison is made. </dd>
@@ -104,12 +109,12 @@ This is the simplest validator, ensuring that the input field has some sort of v
<dt>Integer</dt>
<dd>A 32-bit signed integer data type. </dd>
- <dt>Double</dt>
+ <dt>Float</dt>
<dd>A double-precision floating point number data type. </dd>
-
+
<dt>Currency</dt>
<dd>A decimal data type that can contain currency symbols. </dd>
-
+
<dt>Date</dt>
<dd>A date data type, the date format depends on the <tt>DateFormat</tt> property.</dd>
@@ -120,16 +125,24 @@ This is the simplest validator, ensuring that the input field has some sort of v
<p>Use the <tt>Operator</tt> property to specify the type of comparison to perform. If you set the <tt>Operator</tt> property to <tt>DataTypeCheck</tt>, the <tt>TCompareValidator</tt> component will ignore the <tt>ControlToCompare</tt> and <tt>ValueToCompare</tt> properties and simply indicates whether the value entered into the input component can be converted to the data type specified by the <tt>ValueType</tt> property. </p>
<p>Note that if the input control is empty, no validation functions are called and validation succeeds. Use a <tt>RequiredFieldValidator</tt> control to require the user to enter data into the input control. </p>
+<com:RunBar PagePath="Controls.Samples.TCompareValidator.Home" />
+<h2>TRangeValidator</h2>
+<p>
+</p>
+<com:RunBar PagePath="Controls.Samples.TRangeValidator.Home" />
-
-<com:RunBar PagePath="Controls.Samples.TCompareValidator.Home" />
+<h2>TValueTypeValidator</h2>
+<p>
+</p>
+<com:RunBar PagePath="Controls.Samples.TValueTypeValidator.Home" />
<h2>TCustomValidator</h2>
<p>
</p>
<com:RunBar PagePath="Controls.Samples.TCustomValidator.Home" />
+
<h2>TValidationSummary</h2>
<p>
</p>
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index c142d8a6..0734fa1f 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -216,9 +216,9 @@ emaillogroute_sentfrom_required = TEmailLogRoute.SentFrom cannot be empty.
repeatinfo_repeatcolumns_invalid = TRepeatInfo.RepeatColumns must be no less than 0.
-basevalidator_associatedcontrolid_unsupported = TBaseValidator.AssociatedControlID is not supported.
-basevalidator_controltovalidate_invalid = TBaseValidator.ControlToValidate is empty or contains an invalid control ID path.
-basevalidator_validatable_required = TBaseValidator.ControlToValidate must point to a control implementing IValidatable interface.
+basevalidator_controltovalidate_invalid = %s.ControlToValidate is empty or contains an invalid control ID path.
+basevalidator_validatable_required = %s.ControlToValidate must point to a control implementing IValidatable interface.
+basevalidator_forcontrol_unsupported = %s.ForControl is not supported.
comparevalidator_controltocompare_invalid = TCompareValidator.ControlToCompare contains an invalid control ID path.
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index 46f031ca..03362110 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -370,7 +370,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
if(($id=$this->getControlToValidate())!=='' && ($control=$this->findControl($id))!==null)
return $control;
else
- throw new TConfigurationException('basevalidator_controltovalidate_invalid');
+ throw new TConfigurationException('basevalidator_controltovalidate_invalid',get_class($this));
}
/**
@@ -384,7 +384,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
if($control instanceof IValidatable)
return $control->getValidationPropertyValue();
else
- throw new TInvalidDataTypeException('basevalidator_validatable_required');
+ throw new TInvalidDataTypeException('basevalidator_validatable_required',get_class($this));
}
/**
diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php
index 853cff17..9b8dabd5 100644
--- a/framework/Web/UI/WebControls/TCompareValidator.php
+++ b/framework/Web/UI/WebControls/TCompareValidator.php
@@ -206,7 +206,7 @@ class TCompareValidator extends TBaseValidator
return array($value1, $value2);
case 'Date':
$dateFormat = $this->getDateFormat();
- if (strlen($dateFormat))
+ if($dateFormat!=='')
{
$formatter = Prado::createComponent('System.Data.TSimpleDateFormatter', $dateFormat);
return array($formatter->parse($value1), $formatter->parse($value2));
diff --git a/framework/Web/UI/WebControls/TEmailAddressValidator.php b/framework/Web/UI/WebControls/TEmailAddressValidator.php
index b6ceff90..3534d1d0 100644
--- a/framework/Web/UI/WebControls/TEmailAddressValidator.php
+++ b/framework/Web/UI/WebControls/TEmailAddressValidator.php
@@ -19,8 +19,9 @@ Prado::using('System.Web.UI.WebControls.TRegularExpressionValidator');
* TEmailAddressValidator class
*
* TEmailAddressValidator validates whether the value of an associated
- * input component is a valid email address. It will check MX record
- * if checkdnsrr() is available in the installed PHP.
+ * input component is a valid email address. If {@link getCheckMXRecord CheckMXRecord}
+ * is true, it will check MX record for the email adress, provided
+ * checkdnsrr() is available in the installed PHP.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -50,7 +51,7 @@ class TEmailAddressValidator extends TRegularExpressionValidator
public function evaluateIsValid()
{
$valid=parent::evaluateIsValid();
- if($valid && function_exists('checkdnsrr'))
+ if($valid && $this->getCheckMXRecord() && function_exists('checkdnsrr'))
{
if(($value=$this->getValidationValue($this->getValidationTarget()))!=='')
{
@@ -65,6 +66,23 @@ class TEmailAddressValidator extends TRegularExpressionValidator
}
return $valid;
}
+
+ /**
+ * @return boolean whether to check MX record for the email address being validated. Defaults to true.
+ */
+ public function getCheckMXRecord()
+ {
+ return $this->getViewState('CheckMXRecord',true);
+ }
+
+ /**
+ * @param boolean whether to check MX record for the email address being validated.
+ * Note, if {@link checkdnsrr} is not available, this check will not be performed.
+ */
+ public function setCheckMXRecord($value)
+ {
+ $this->setViewState('CheckMXRecord',TPropertyValue::ensureBoolean($value),true);
+ }
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TRegularExpressionValidator.php b/framework/Web/UI/WebControls/TRegularExpressionValidator.php
index f20c2d16..4271c820 100644
--- a/framework/Web/UI/WebControls/TRegularExpressionValidator.php
+++ b/framework/Web/UI/WebControls/TRegularExpressionValidator.php
@@ -29,7 +29,6 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator');
* German Phone Number: ((\(0\d\d\) |(\(0\d{3}\) )?\d )?\d\d \d\d \d\d|\(0\d{4}\) \d \d\d-\d\d?)
* German Postal Code: (D-)?\d{5}
* Email Address: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
- * Internal URL: http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
* Japanese Phone Number: (0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}
* Japanese Postal Code: \d{3}(-(\d{4}|\d{2}))?
* P.R.C. Phone Number: (\(\d{3}\)|\d{3}-)?\d{8}
diff --git a/framework/Web/UI/WebControls/TValueTypeValidator.php b/framework/Web/UI/WebControls/TValueTypeValidator.php
index ca4a01ca..8b5d7bbc 100644
--- a/framework/Web/UI/WebControls/TValueTypeValidator.php
+++ b/framework/Web/UI/WebControls/TValueTypeValidator.php
@@ -1,14 +1,29 @@
<?php
+/**
+ * TValueTypeValidator class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
/**
- * TRequiredValueTypeValidator class.
+ * Using TBaseValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TBaseValidator');
+
+/**
+ * TValueTypeValidator class
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TValueTypeValidator
+class TValueTypeValidator extends TBaseValidator
{
/**
* @return string the data type that the values being compared are converted to before the comparison is made. Defaults to String.
@@ -72,7 +87,7 @@ class TValueTypeValidator
return strtotime($value) > 0;
}
return true;
- }
+ }
/**
* This method overrides the parent's implementation.