本文整理汇总了PHP中Validator::email方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::email方法的具体用法?PHP Validator::email怎么用?PHP Validator::email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validator
的用法示例。
在下文中一共展示了Validator::email方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetupRecursively
public function testSetupRecursively()
{
$handler = $this->getMock('\\PHPVS\\RuleSet');
$handler->expects($this->atLeastOnce())->method('handle');
RuleSet::filter(['array' => ['age' => -1, 'email' => 'not an email']], ['array' => RuleSet::setup(['age' => Validator::int()->prepare(), 'email' => Validator::email()->prepare()], $required = true)], "", $handler);
// test not required
$handler2 = $this->getMock('\\PHPVS\\RuleSet');
$handler2->expects($this->never())->method('handle');
RuleSet::filter(['array' => ['age' => "", 'email' => ""]], ['array' => RuleSet::setup(['age' => Validator::int()->required(false)->prepare(), 'email' => Validator::email()->required(false)->prepare()], $required = true)], "", $handler2);
}
示例2: testEmailValidation
public function testEmailValidation()
{
$validator = new Validator();
$this->assertEquals('me@website.com', $validator->email('me@website.com'));
$this->assertEquals('me@website.com,you@some-other-website.com', $validator->email('me@website.com,you@some-other-website.com'));
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('me@you'));
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('asdfasdf'));
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array(42));
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('me@website.com,asdf'));
// Extra whitespace is trimmed by default
$this->assertEquals('some.guy@www.some-website.com', $validator->email("\nsome.guy@www.some-website.com "));
$this->assertEquals('some.guy@www.some-website.com,mailer-daemon@yahoo.biz', $validator->email("\nsome.guy@www.some-website.com , mailer-daemon@yahoo.biz"));
// This may be disabled
$this->assertEquals("\nsome.guy@www.some-website.com ", $validator->email("\nsome.guy@www.some-website.com ", null, 0));
$this->assertEquals("\nsome.guy@www.some-website.com , mailer-daemon@yahoo.biz", $validator->email("\nsome.guy@www.some-website.com , mailer-daemon@yahoo.biz", null, 0));
// Filter to upper- or lowercase
$this->assertEquals('hello@me.com', $validator->email('hELLO@ME.COM ', null, Validator::FILTER_DEFAULT | Validator::FILTER_LOWERCASE));
$this->assertEquals('HELLO@ME.COM,HELLO@YOU.COM', $validator->email('hELLO@ME.COM , Hello@you.com', null, Validator::FILTER_DEFAULT | Validator::FILTER_UPPERCASE));
// The default filtering trims and coerces empty values to null
$this->assertNull($validator->email(null));
$this->assertNull($validator->email(''));
$this->assertNull($validator->email(" \n"));
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array(null, null, 0));
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('', null, 0));
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array(" \n", null, 0));
/* By default, comma-delimited lists of email address are treated as
valid. This may be disabled with an assertion. */
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('me@website.com,you@some-other-website.com', null, Validator::FILTER_DEFAULT | Validator::ASSERT_SINGLE_EMAIL));
$this->assertThrows('InvalidArgumentException', array($validator, 'email'), array("\nsome.guy@www.some-website.com , mailer-daemon@yahoo.biz", null, Validator::FILTER_DEFAULT | Validator::ASSERT_SINGLE_EMAIL));
}
示例3: testEmail
public function testEmail()
{
$this->assertTrue(Validator::email('valid@email.com'));
$this->assertFalse(Validator::email('Some random garbage'));
$this->assertFalse(Validator::email(array()));
}
示例4: subscribeNewsletter
public function subscribeNewsletter()
{
$validator = new Validator();
$req = array('subscriber_email' => t("Email is required"));
$req_email = array('subscriber_email' => t("Email address seems invalid"));
$validator->required($req, $this->data);
$validator->email($req_email, $this->data);
if (Yii::app()->functions->getSubsriberEmail($this->data['subscriber_email'])) {
$validator->msg[] = t("Sorry your Email address is already exist in our records.");
}
if ($validator->validate()) {
$params = array('email_address' => $this->data['subscriber_email'], 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR']);
if ($this->insertData("{{newsletter}}", $params)) {
$this->code = 1;
$this->msg = t("Thank you for subscribing to our mailing list!");
} else {
$this->msg = t("Sorry there is error while we saving your information.");
}
} else {
$this->msg = $validator->getErrorAsHTML();
}
}
示例5: Validator
<?php
namespace Project\Validation;
include_once '../autoloader.php';
// Test data
$v = new Validator(['name' => 'asdfsdf', 'age' => '20', 'phone' => '123123', 'email' => 'aoidsf@213.com', 'password' => 'wang1@']);
// Validate one field with multiple rules
$v->validate('name', ['notEmpty', ['greaterThan', 100], ['between', 0, 20]]);
$v->validate('age', ['notEmpty', ['between', 0, 100]]);
//length validation
//equal validation
$v->validate('name', [['length', 7]]);
$v->validate('name', [['equal', true]]);
// Email
$v->email()->validate('age', [['EmailValidator', '123.com']]);
// Call additional validator
echo $v->address()->street(3) . '<br>';
// Use getKey method to validate key value
echo $v->phone()->phoneNumber('12345') . '<br>';
echo $v->phone()->phoneNumber($v->getKey('phone')) . '<br>';
echo 'street', $v->address()->validate('email', ['street']) . '<br>';
//password validation
echo $v->password()->password($v->getKey('password')) . '<br>';
// Errors
echo '<hr/>';
if ($v->isValid()) {
echo 'all valid';
} else {
echo 'error on age field: ';
$v->displayError('age');
示例6: register
function register($params)
{
global $App, $Database;
// if logged in, waste time no longer..
if ($this->Auth->isLoggedIn()) {
$User = $this->Auth->getUser();
$this->redirect(array('controller' => 'users', 'action' => 'profile', 'params' => array($User->id)), array('success' => array('You were already logged in! ;)')));
}
if (($submitdata = $App->Form->get_submit_data('user_register')) == true) {
$error = false;
// check name
if (strlen(trim($submitdata['name'])) > 50) {
$App->setFlash(array('error' => array('Your name must be shorter than 50 characters')));
$App->Form->set_error_input(array('group' => 'user_register', 'name' => 'name'));
$error = true;
}
if (strlen(trim($submitdata['name'])) == 0) {
$App->setFlash(array('error' => array("Don't you have a name? How should we address you?")));
$App->Form->set_error_input(array('group' => 'user_register', 'name' => 'name'));
$error = true;
}
$users = $Database->fetchObjects('User', "\r\n\t\t\t\tSELECT `id` FROM `users` WHERE `name` = '" . trim($submitdata['name']) . "'\r\n\t\t\t");
if (count($users) != 0) {
$App->setFlash(array('news' => array('A user already exists with this name. Could this be you?<br />' . 'Maybe you just <a href="' . $App->ml(array('controller' => 'users', 'action' => 'forgot_password')) . '">forgot your password</a>?')));
$App->Form->set_error_input(array('group' => 'user_register', 'name' => 'name'));
$error = true;
}
// check password
if (!Validator::password(trim($submitdata['password']))) {
$App->setFlash(array('error' => array('Your password is empty! Please do choose a password.')));
$App->Form->set_error_input(array('group' => 'user_register', 'name' => 'password'));
$error = true;
}
// check email
if (!Validator::email(trim($submitdata['email']))) {
$App->setFlash(array('error' => array('Please check your email address; the system validates it as false..')));
$App->Form->set_error_input(array('group' => 'user_register', 'name' => 'email'));
$error = true;
} else {
$users = $Database->fetchObjects('User', "\r\n\t\t\t\t\tSELECT `id` FROM `users` WHERE `email` = '" . trim($submitdata['email']) . "'\r\n\t\t\t\t");
if (!empty($users)) {
$App->setFlash(array('news' => array('A user already exists with this email address! Is this you?<br />' . 'His or her name is ' . $users[0]->data['name'] . '.<br />' . 'Go to the <a href="' . $App->ml(array('controller' => 'users', 'action' => 'login')) . '">log in</a> page?<br />' . '.. or maybe you just <a href="' . $App->ml(array('controller' => 'users', 'action' => 'forgot_password')) . '">forgot your password</a>?')));
$error = true;
}
}
if (!$error) {
// checking done,
// REGISTER
$key = '';
$chars = '1234567890qwertyuiopasdfghjklzxcvbnm';
for ($i = 0; $i <= 30; $i++) {
$key .= substr($chars, rand(0, strlen($chars) - 1), 1);
}
$sql = "\r\n\t\t\t\t\tINSERT INTO `users` (`name`, `password`, `email`, `key`) VALUES\r\n\t\t\t\t\t('" . trim($submitdata['name']) . "', '" . trim($submitdata['password']) . "', '" . trim($submitdata['email']) . "', '{$key}')\r\n\t\t\t\t";
mysql_query($sql) or die('lw3uhgksdnh,snd,h <pre>' . $sql . '</pre> ' . mysql_error());
$id = mysql_insert_id();
$users = $Database->fetchObjects('User', "SELECT {$id}");
$User = $users[0];
// send confirmation email
$mail_sent = @mail($User->data['name'] . ' <' . $User->data['email'] . '>', 'PHPScrabble - Confirm your email address', 'Please follow this link to confirm your email address: ' . $App->ml(array('controller' => 'users', 'action' => 'confirm_email', 'params' => array($key))), 'From: info@phpscrabble.com' . "\r\n" . 'Reply-To: info@phpscrabble.com');
$this->redirect(array('controller' => 'users', 'action' => 'login'), array('success' => array('You have successfully registered!<br />' . 'Please check your email for a comfirmation link.<br />' . 'After you\'ve comfirmed your email address you van log in and start playing scrabble.')));
}
}
}
示例7: oauth_bind_act
/**
* 绑定用户Action
*/
public function oauth_bind_act()
{
$userinfo = Session::get('oauth_user_info');
if ($userinfo) {
$email = Filter::sql(Req::args('email'));
$passWord = Req::post('password');
$rePassWord = Req::post('repassword');
if (!Validator::email($email)) {
$info = array('field' => 'email', 'msg' => '邮箱不能为空!');
} elseif (strlen($passWord) < 6) {
$info = array('field' => 'password', 'msg' => '密码长度必需大于6位!');
} else {
$model = $this->model->table("user as us");
$obj = $model->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find();
if ($obj) {
if ($obj['password'] == CHash::md5($passWord, $obj['validcode'])) {
$test = $this->model->table('oauth_user')->where("oauth_type='{$userinfo['oauth_type']}' and open_id='{$userinfo['open_id']}'")->data(array('user_id' => $obj['id']))->update();
$this->safebox->set('user', $obj, 1800);
$this->redirect("/ucenter/index");
} else {
$info = array('field' => 'password', 'msg' => '密码与用户名是不匹配的,无法绑定!');
}
} else {
if ($passWord == $rePassWord) {
$model = $this->model->table("user");
$validcode = CHash::random(8);
$last_id = $model->data(array('email' => $email, 'name' => $userinfo['open_name'], 'password' => CHash::md5($passWord, $validcode), 'validcode' => $validcode))->insert();
$time = date('Y-m-d H:i:s');
$model->table("customer")->data(array('user_id' => $last_id, 'reg_time' => $time, 'login_time' => $time))->insert();
//记录登录信息
$obj = $model->table("user as us")->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find();
$this->safebox->set('user', $obj, 1800);
$this->model->table('oauth_user')->where("oauth_type='{$userinfo['oauth_type']}' and open_id='{$userinfo['open_id']}'")->data(array('user_id' => $last_id))->update();
$this->redirect("/ucenter/index");
} else {
$info = array('field' => 'repassword', 'msg' => '两次密码输入不一致!');
}
}
}
$this->assign("invalid", $info);
$this->redirect("/simple/oauth_bind", false, Req::args());
} else {
$this->redirect("/index/index");
}
}
示例8: createValidator
/**
* Creates a Validator object that checks against each of the function arguemnts
*
* @param integer ...
* @return Validator
*/
public function createValidator()
{
$validator = new Validator($this);
foreach (func_get_args() as $ruleCode) {
switch ($ruleCode) {
case self::ANYTHING:
$validator->forceResult(TRUE);
break;
case self::ANYTHING_COLLECTION:
$validator->orValidator($this->createValidator()->isEmpty(), $this->createValidator()->collectionValidator($this->createValidator()->forceResult(TRUE)));
break;
case self::USERNAME_COLLECTION:
$validator->orValidator($this->createValidator()->isEmpty(), $this->createValidator()->collectionValidator($this->createValidator()->username()));
break;
case self::SERVICESTATUS:
$validator->memberOf('enabled', 'disabled');
break;
case self::USERNAME:
$validator->username();
break;
case self::HOSTNAME:
$validator->hostname();
break;
case self::HOSTNAME_FQDN:
$validator->hostname(1);
break;
case self::HOSTNAME_SIMPLE:
$validator->hostname(0, 0);
break;
case self::HOSTADDRESS:
$validator->orValidator($this->createValidator()->ipV4Address(), $this->createValidator()->hostname());
break;
case self::NOTEMPTY:
$validator->notEmpty();
break;
case self::DATE:
$validator->date();
break;
case self::TIME:
$validator->time();
break;
case self::IP:
case self::IPv4:
$validator->ipV4Address();
break;
case self::NETMASK:
case self::IPv4_NETMASK:
$validator->ipV4Netmask();
break;
case self::MACADDRESS:
$validator->macAddress();
break;
case self::POSITIVE_INTEGER:
$validator->integer()->positive();
break;
case self::NONNEGATIVE_INTEGER:
$validator->integer()->greatThan(-1);
break;
case self::PORTNUMBER:
$validator->integer()->greatThan(0)->lessThan(65535);
break;
case self::BOOLEAN:
$validator->memberOf('1', 'yes', '0', '');
break;
case self::IP_OR_EMPTY:
case self::IPv4_OR_EMPTY:
$validator->orValidator($this->createValidator()->ipV4Address(), $this->createValidator()->isEmpty());
break;
case self::NETMASK_OR_EMPTY:
case self::IPv4_NETMASK_OR_EMPTY:
$validator->orValidator($this->createValidator()->ipV4Netmask(), $this->createValidator()->isEmpty());
break;
case self::YES_NO:
$validator->memberOf('yes', 'no');
break;
case self::EMAIL:
$validator->email();
break;
case self::EMPTYSTRING:
$validator->maxLength(0);
break;
case self::CIDR_BLOCK:
$validator->cidrBlock();
break;
case NULL:
continue;
default:
throw new \InvalidArgumentException(sprintf('%s: Unknown validator code: %s', get_class($this), $ruleCode), 1326380984);
}
}
return $validator;
}
示例9: send_email_test
public function send_email_test()
{
$test_email = Req::args('email');
if (Validator::email($test_email)) {
$mail = new Mail();
try {
$flag = $mail->send_email($test_email, 'TinyShop电子商务系统,邮箱验证测试', "<div><h3>亲爱的TinyShop用户您好:</h3><p style='text-indent:2em;'>当您收到这封邮件时,说明您的信息配制正确,邮件系统可以正常工作。</p></div>");
$info = array('status' => 'success', 'msg' => '测试成功,邮件已发送');
if (!$flag) {
$info = array('status' => 'fail', 'msg' => '测试失败,请检测配制信息');
}
echo JSON::encode($info);
} catch (Exception $e) {
$msg = $e->errorMessage();
$info = array('status' => 'fail', 'msg' => $msg);
echo JSON::encode($info);
}
} else {
$info = array('status' => 'fail', 'msg' => '测试邮箱地址格式不正确,核实后再测试');
echo JSON::encode($info);
}
}
示例10: validateArray
static function validateArray(&$array, &$rules)
{
// Workaround for non Fancy-URL user.
$cropArray = array();
foreach ($array as $name => $value) {
$doesHaveRequest = strpos($name, '?');
if ($doesHaveRequest !== false) {
$name = substr($name, $doesHaveRequest + 1);
}
$cropArray[$name] = $value;
}
$array = $cropArray;
foreach ($rules as $key => $rule) {
if (!isset($rule[0])) {
trigger_error("Validator: The type of '{$key}' is not defined", E_USER_WARNING);
continue;
}
if (isset($array[$key]) && ($rule[0] == 'file' || strlen($array[$key]) > 0)) {
$value =& $array[$key];
if (isset($rule['min'])) {
$rule[1] = $rule['min'];
}
if (isset($rule['max'])) {
$rule[2] = $rule['max'];
}
if (isset($rule['bypass'])) {
$rule[3] = $rule['bypass'];
}
switch ($rule[0]) {
case 'any':
if (isset($rule[1]) && strlen($value) < $rule[1]) {
return false;
}
if (isset($rule[2]) && strlen($value) > $rule[2]) {
return false;
}
break;
case 'bit':
$array[$key] = Validator::getBit($value);
break;
case 'bool':
$array[$key] = Validator::getBool($value);
break;
case 'number':
if (!Validator::number($value, isset($rule[1]) ? $rule[1] : null, isset($rule[2]) ? $rule[2] : null, isset($rule[3]) ? $rule[3] : false)) {
return false;
}
break;
case 'int':
if (!Validator::isInteger($value, isset($rule[1]) ? $rule[1] : -2147483648.0, isset($rule[2]) ? $rule[2] : 2147483647, isset($rule[3]) ? $rule[3] : false)) {
return false;
}
break;
case 'id':
if (!Validator::id($value, isset($rule[1]) ? $rule[1] : 1, isset($rule[2]) ? $rule[2] : 2147483647)) {
return false;
}
break;
case 'url':
case 'string':
if (!Utils_Unicode::validate($value)) {
$value = Utils_Unicode::bring($value);
if (!Utils_Unicode::validate($value)) {
return false;
}
}
$value = $array[$key] = Utils_Unicode::correct($value);
if (isset($rule[1]) && Utils_Unicode::length($value) < $rule[1]) {
return false;
}
if (isset($rule[2]) && Utils_Unicode::length($value) > $rule[2]) {
return false;
}
break;
case 'list':
if (!Validator::isList($value)) {
return false;
}
break;
case 'timestamp':
if (!Validator::timestamp($value)) {
return false;
}
break;
case 'period':
if (!Validator::period($value)) {
return false;
}
break;
case 'ip':
if (!Validator::ip($value)) {
return false;
}
break;
case 'domain':
if (!Validator::domain($value)) {
return false;
}
break;
case 'email':
//.........这里部分代码省略.........
示例11: User
$method = $methods[$i];
$tocheck = $_GET[$methods[$i]];
}
}
switch ($method) {
case 'username':
$user = new User($tocheck);
if ($user->FetchData()) {
echo "0";
} else {
echo "1";
}
break;
case 'email':
$valid = new Validator($tocheck);
if ($valid->email()) {
echo 1;
} else {
echo 0;
}
break;
case 'queryUsernames':
//there are should be check for admin rights
//echo User::getInstance()->FetchNamesLike($tocheck);
$names = User::getInstance()->FetchNamesLike($tocheck);
$ret['query'] = $method;
for ($i = 0; $i < count($names); $i++) {
$ret['suggestions'] = $names[$i]['username'];
}
echo json_encode($ret);
break;
示例12: testEmail4
/**
* Generated from @assert ('admin@ไทย') [==] true.
*
* @covers Validator::email
*/
public function testEmail4()
{
$this->assertTrue(\Validator::email('admin@ไทย'));
}
示例13: testEmail
public function testEmail()
{
$this->assertFalse(Validator::email()->valid("not an email"));
$this->assertTrue(Validator::email()->valid("php@html.js.cn"));
}
示例14: join
public function join()
{
if (!empty($_POST)) {
$valid = true;
if (empty($_POST['username'])) {
$this->message->put(Language::gettext('login-empty-required-field', 'login-form-username'));
$valid = false;
}
if (empty($_POST['password'])) {
$this->message->put(Language::gettext('login-empty-required-field', 'login-form-password'));
$valid = false;
}
if (empty($_POST['repassword']) || $_POST['password'] != $_POST['repassword']) {
$this->message->put(Language::gettext('login-empty-required-field', 'login-form-password-confirm'));
$valid = false;
} else {
if ($valid) {
if ($_POST['password'] != $_POST['repassword']) {
$this->message->put(Language::gettext('login-required-password-confirm'));
$valid = false;
}
}
}
if (empty($_POST['full_name'])) {
$this->message->put(Language::gettext('login-empty-required-field', 'login-form-username'));
$valid = false;
}
if (empty($_POST['gender'])) {
$this->message->put(Language::gettext('login-empty-required-field', 'login-form-gender'));
$valid = false;
}
if (empty($_POST['dob'])) {
$this->message->put(Language::gettext('login-empty-required-field', 'login-form-dob'));
$valid = false;
}
if (empty($_POST['sin'])) {
$this->message->put(Language::gettext('login-empty-required-field', 'login-form-sin'));
$valid = false;
}
if (empty($_POST['email']) || !Validator::email($_POST['email'])) {
$this->message->put(Language::gettext('login-empty-required-field', 'login-form-email'));
$valid = false;
}
if (empty($_POST['phone_home']) && empty($_POST['phone_cell']) && empty($_POST['phone_work'])) {
$this->message->put(Language::gettext('login-required-contact-info'));
$valid = false;
}
if ($valid) {
$session_user = Session::get(Session::USER);
$user = new User($_POST);
$user->created = $session_user->created;
$user->last = time();
$user->access = User::MEMBER;
$user->password = User::encryptPassword($_POST['password'], $_POST['username']);
$user->update();
}
if (!empty($user->user_id)) {
Session::set(Session::USER, $user);
}
}
if (!empty($user->user_id) && Session::isLoggedIn()) {
$this->followup();
} else {
unset($_POST['username']);
unset($_POST['password']);
$this->login();
}
}
示例15: _validateArgs
/**
* Validates the high-level arguments (not the arguments related to
* queries) and sets the appropriate properties.
*
* @param array &$args
*/
private function _validateArgs(array &$args)
{
if (isset($args['formatter'])) {
if (class_exists($args['formatter']) && (is_subclass_of($args['formatter'], 'Google\\Analytics\\ReportFormatter') || $args['formatter'] == 'Google\\Analytics\\ReportFormatter')) {
$this->_formatter = new $args['formatter']();
} else {
throw new InvalidArgumentException('Invalid report formatter class name.');
}
} else {
$this->_formatter = new ReportFormatter();
}
if (isset($args['email'])) {
$v = new \Validator(__NAMESPACE__);
$email = $v->email($args['email'], '"' . $args['email'] . '" is not a valid email address.', \Validator::FILTER_TRIM | \Validator::ASSERT_TRUTH);
$this->_email = new \Email($email);
}
if (isset($args['file'])) {
$this->_fileName = $args['file'];
}
if (!$this->_email && !$this->_fileName) {
throw new InvalidArgumentException('An email address and/or an output file must be specified.');
}
}