yii 框架 View 中的 javascript 验证电子邮件

标签 javascript php html yii

<script type="text/javascript">
function validate() {
    var email = document.getElementById('email').value;
    var phone = document.getElementById('phone').value;

    var emailFilter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    var phoneFilter = /^http:\/\//;

    if (!emailFilter.test(email)) {
        alert('Please enter a valid e-mail address.');
        return false;
    }

    if (!phoneFilter.test(phone)) {
        alert('Please correct your phone number.');
        return false;
    }

    return true;
}

</script>

<?php echo $form->textFieldRow($model,'login',array('class'=>'span5','type'=>'email','id'=>'email','maxlength'=>50,'labelOptions' => array('label' => false))); ?>

我在没有运行此 yii 框架的情况下应用了 html 表单 但使用 yii 框架时则不然

最佳答案

您可以使用 Yii 表单来实现此目的。

如果你使用 Yii,这将是比在 js 上编写验证更好的解决方案。

您可以看到的示例 here .

关于yii 框架 View 中的 javascript 验证电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52713978/

相关文章:

html - 使用之前和之后的可调整图像

html - css: li 元素在水平方向的奇怪和困惑的布局

Javascript 和 jQuery 文件结构

javascript - AngularJS 中的 HTTPS 'GET'

javascript match 获取所有带有数字的类名

javascript - Handsontable firstrow 错位

php - 如何从 Vue 对 Laravel 执行批量删除?

javascript - 如何将像素转换为measurement-html5 Canvas

javascript - 进行 php ajax 类型回调的正确方法

php - 如何阻止 PHP 在文件开头添加 LF 前缀