Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
4b30fe8b
Commit
4b30fe8b
authored
May 02, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished js validation for email and regular expression validators.
parent
41b127b9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
22 deletions
+58
-22
yii.validation.js
framework/assets/yii.validation.js
+20
-0
CompareValidator.php
framework/validators/CompareValidator.php
+1
-1
EmailValidator.php
framework/validators/EmailValidator.php
+13
-11
RegularExpressionValidator.php
framework/validators/RegularExpressionValidator.php
+15
-10
RequiredValidator.php
framework/validators/RequiredValidator.php
+9
-0
No files found.
framework/assets/yii.validation.js
View file @
4b30fe8b
...
...
@@ -79,6 +79,26 @@ yii.validation = (function ($) {
||
options
.
strict
&&
(
value
===
options
.
trueValue
||
value
===
options
.
falseValue
);
valid
||
messages
.
push
(
options
.
message
);
},
email
:
function
(
value
,
messages
,
options
)
{
if
(
options
.
skipOnEmpty
&&
isEmpty
(
value
))
{
return
;
}
var
valid
=
value
.
match
(
options
.
pattern
)
&&
(
!
options
.
allowName
||
value
.
match
(
options
.
fullPattern
));
valid
||
messages
.
push
(
options
.
message
);
},
regularExpression
:
function
(
value
,
messages
,
options
)
{
if
(
options
.
skipOnEmpty
&&
isEmpty
(
value
))
{
return
;
}
if
(
!
value
.
match
(
options
.
pattern
))
{
messages
.
push
(
options
.
message
)
}
}
};
})(
jQuery
);
framework/validators/CompareValidator.php
View file @
4b30fe8b
...
...
@@ -197,7 +197,7 @@ class CompareValidator extends Validator
$options
[
'skipOnEmpty'
]
=
1
;
}
$options
[
'message'
]
=
Html
::
encode
(
strtr
(
$
options
[
'message'
]
,
array
(
$options
[
'message'
]
=
Html
::
encode
(
strtr
(
$
this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
'{compareValue}'
=>
$compareValue
,
...
...
framework/validators/EmailValidator.php
View file @
4b30fe8b
...
...
@@ -8,6 +8,9 @@
namespace
yii\validators
;
use
Yii
;
use
yii\helpers\Html
;
use
yii\helpers\JsExpression
;
use
yii\helpers\Json
;
/**
* EmailValidator validates that the attribute value is a valid email address.
...
...
@@ -100,20 +103,19 @@ class EmailValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
$message
=
strtr
(
$this
->
message
,
array
(
$options
=
array
(
'pattern'
=>
new
JsExpression
(
$this
->
pattern
),
'fullPattern'
=>
new
JsExpression
(
$this
->
fullPattern
),
'allowName'
=>
$this
->
allowName
,
'message'
=>
Html
::
encode
(
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
));
$condition
=
"!value.match(
{
$this
->
pattern
}
)"
;
if
(
$this
->
allowName
)
{
$condition
.=
" && !value.match(
{
$this
->
fullPattern
}
)"
;
))),
);
if
(
$this
->
skipOnEmpty
)
{
$options
[
'skipOnEmpty'
]
=
1
;
}
return
"
if("
.
(
$this
->
skipOnEmpty
?
"$.trim(value)!='' && "
:
''
)
.
$condition
.
") {
messages.push("
.
json_encode
(
$message
)
.
");
}
"
;
return
'yii.validation.email(value, messages, '
.
Json
::
encode
(
$options
)
.
');'
;
}
}
framework/validators/RegularExpressionValidator.php
View file @
4b30fe8b
...
...
@@ -9,6 +9,9 @@ namespace yii\validators;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\Html
;
use
yii\helpers\JsExpression
;
use
yii\helpers\Json
;
/**
* RegularExpressionValidator validates that the attribute value matches the specified [[pattern]].
...
...
@@ -81,11 +84,6 @@ class RegularExpressionValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
));
$pattern
=
$this
->
pattern
;
$pattern
=
preg_replace
(
'/\\\\x\{?([0-9a-fA-F]+)\}?/'
,
'\u$1'
,
$pattern
);
$deliminator
=
substr
(
$pattern
,
0
,
1
);
...
...
@@ -100,10 +98,17 @@ class RegularExpressionValidator extends Validator
$pattern
.=
preg_replace
(
'/[^igm]/'
,
''
,
$flag
);
}
return
"
if ("
.
(
$this
->
skipOnEmpty
?
"$.trim(value)!='' && "
:
''
)
.
(
$this
->
not
?
''
:
'!'
)
.
"value.match(
$pattern
)) {
messages.push("
.
json_encode
(
$message
)
.
");
}
"
;
$options
=
array
(
'pattern'
=>
new
JsExpression
(
$pattern
),
'message'
=>
Html
::
encode
(
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
))),
);
if
(
$this
->
skipOnEmpty
)
{
$options
[
'skipOnEmpty'
]
=
1
;
}
return
'yii.validation.regularExpression(value, messages, '
.
Json
::
encode
(
$options
)
.
');'
;
}
}
framework/validators/RequiredValidator.php
View file @
4b30fe8b
...
...
@@ -40,6 +40,15 @@ class RequiredValidator extends Validator
* to check if the attribute value is empty.
*/
public
$strict
=
false
;
/**
* @var string the user-defined error message. It may contain the following placeholders which
* will be replaced accordingly by the validator:
*
* - `{attribute}`: the label of the attribute being validated
* - `{value}`: the value of the attribute being validated
* - `{requiredValue}`: the value of [[requiredValue]]
*/
public
$message
;
/**
* Initializes the validator.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment