Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何绑定输入类型=';电子邮件';在淘汰赛中_Javascript_Jquery_Html_Knockout.js_Knockout Mvc - Fatal编程技术网

Javascript 如何绑定输入类型=';电子邮件';在淘汰赛中

Javascript 如何绑定输入类型=';电子邮件';在淘汰赛中,javascript,jquery,html,knockout.js,knockout-mvc,Javascript,Jquery,Html,Knockout.js,Knockout Mvc,我在MVC中使用KnockoutJS 我想知道emailId是有效的还是无效的,根据它,我必须启用/禁用按钮并为textbox设置错误标题 这是我的.cshtml <div class="nmc-righttab" style="width:265px;"> <input class="nmc-text" type="email" maxlength="50" id="txtEmail" data-bind="value: emailAddress, valueUpda

我在MVC中使用KnockoutJS

我想知道emailId是有效的还是无效的,根据它,我必须启用/禁用按钮并为textbox设置错误标题

这是我的.cshtml

<div class="nmc-righttab" style="width:265px;">
    <input class="nmc-text" type="email" maxlength="50" id="txtEmail" data-bind="value: emailAddress, valueUpdate: 'input'",css: { faultyBrush: (checkValidEmail() },attr: {title: InvalidEmailTitle } style="width:245px;" />
 </div> 

 <input type="submit" class="btn nmc-button" data-bind="click: searchUsers,enable: canSearchUsers,css: { 'btn-primary': (canSearchUsers() == true) }" id="searchUser" value="@Res.CommonStrings.Search" />
请让我知道如何知道电子邮件类型文本框的有效性,以及如何在敲除JS中无效的情况下更改相同文本框的标题


如何获取输入类型为“email”的文本框的有效性如果您不想使用验证插件,可以根据您自己的正则表达式测试输入:

HTML


有两种模式。

您可以使用淘汰验证插件。谢谢你的链接。但是我愿意使用输入类型“email”。请建议是否有与email相关的内容。你想什么时候验证email?当用户正在键入或用户单击提交按钮时?如果键入会更好
 this.emailAddress = ko.observable('');
 this.invalidEmailTitle = ko.observable('');
 this.canSearchUsers = ko.computed(function () {
     try {
         if (this.emailAddress().trim().length!==0)
             return true;
         else
              return false;
     } catch (error) {
         NMCApp.showNMCExceptionWindow('Jquery Error:' + error);
     }
}, this);

this.checkValidEmail(input) {

}
<input data-bind="textInput: emailAddress, css: { 'faultyBrush': !checkValidEmail()}" class="nmc-text" type="email" maxlength="50" id="txtEmail" />
var self = this;
self.emailAddress = ko.observable('');
self.checkValidEmail = ko.pureComputed(function () {
    if (!self.emailAddress()) return false;
    var pattern = /REGEX-GOES-HERE/i;
    return pattern.test(self.emailAddress());
});