简体   繁体   English

Email 正则表达式 Javascript 带 RPC

[英]Email RegEx Javascript with RPC

I have a few codes here of js.我这里有一些js代码。 And I wanted to put a validation for email and prevents user from submitting a form when it is not valid.我想对 email 进行验证,并防止用户在表单无效时提交表单。 Please bear with me since I am new with this technology.请耐心等待,因为我是这项技术的新手。 Thank you for understanding:)谢谢你的理解:)

var session = require('web.session');
var db_name = $("input[name='partner_name']").val();
var contact = $("input[name='contact_name']").val();
var email = $("input[name='email_from']").val();
var url = '/page/website_crm.contactus_thanks';


 $(function(){
        $("#start_trial").click(function(){ // no idea how to put email validation here
                    session.rpc('/custom/createaccount', {                      
                            db_name : db_name, 
                            contact_name: contact, 
                            email_from: email
                        });
                    }).then(function () {
                        console.log("Creating user account")
                    });
                    
                   // that won't proceed here
                    setTimeout(function (){
                       window.location = url;
                    }, 5000);

});

if you want to test if email is ok, lot of solution, this pattern does the job:如果你想测试 email 是否正常,很多解决方案,这个模式可以完成工作:

var email = $("input[name='email_from']").val();
var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;

if(!pattern.test(email))
{
  alert('e-mail address is not valid');
}​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM