0

不确定我是否在这里遗漏了某些内容,但似乎当我使用“validateEmail”时,它要求电子邮件地址为小写。如果您在下面运行我的代码并输入您的姓名和带有大写值的电子邮件地址,它将不会提交。但是,如果您删除所有大写值以降低它的工作正常。有谁知道这是设计使然还是错误?

function doGet() {
//  // Create the signup application
 var app = UiApp.createApplication();

  //Create vertical panel to hold the widgets
  var panelMain = app.createVerticalPanel().setId('mainPanel');

  var lblName = app.createLabel('Name:').setId('lblName').setWidth('80px')
  .setStyleAttribute("fontFamily","Trebuchet MS")
  .setStyleAttribute("fontSize","12pt");


  var txtName = app.createTextBox().setName('txtName').setId('txtName').setWidth('300px')
  .setStyleAttribute("background-color", "#ffbb00")
  .setStyleAttribute("fontFamily", "Trebuchet MS")
  .setStyleAttribute("fontSize", "12pt");

  var lblEmail = app.createLabel('Email:').setId('lblEmail').setWidth('80px')
  .setStyleAttribute("fontFamily","Trebuchet MS")
  .setStyleAttribute("fontSize","12pt");

  var txtEmail = app.createTextBox().setName('txtEmail').setId('txtEmail').setWidth('300px')
  .setStyleAttribute("background-color", "#ffbb00")
  .setStyleAttribute("fontFamily", "Trebuchet MS")
  .setStyleAttribute("fontSize", "12pt");

  var lblRequiredEmail = app.createLabel('*').setId('lblRequiredEmail');
  var lblRequiredName = app.createLabel('*').setId('lblRequiredName');
  var lblStatus = app.createLabel("Sign up to receive specials and promotions.").setId('lblStatus')
  .setStyleAttribute("fontFamily","Trebuchet MS")
  .setStyleAttribute("fontSize","12pt");

  var btnSubmit = app.createButton("Submit").setId("btnSubmit").setWidth("120px")
  .setStyleAttribute("fontFamily", "Trebuchet MS")
  .setStyleAttribute("fontSize", "12pt")


  var gridMain = app.createGrid(4, 3).setId('gridMain');

 gridMain.setWidget(0,0,lblName)
 .setWidget(0,1,txtName)
 .setWidget(0, 2, lblRequiredName)
 .setWidget(1, 0,lblEmail)
 .setWidget(1, 1,txtEmail)
  .setWidget(1,2,lblRequiredEmail)
 .setWidget(2,1,btnSubmit);

  panelMain.add(lblStatus).add(gridMain);




  //Create server handler for when user submits the information
  var serverHandler = app.createServerHandler('Signup')
 .validateEmail(txtEmail)
 .validateLength(txtName,1,500)
 .addCallbackElement(panelMain);


  var validateEmail = app.createClientHandler()
  .validateNotEmail(txtEmail)
  .forTargets(txtEmail).setStyleAttribute("color", "red")
  .forTargets(lblRequiredEmail).setVisible(true)
  .setText('Invalid Email')
  .setStyleAttribute("color", "red");


  var validateName = app.createClientHandler()
  .validateNotLength(txtName,1,500)
  .forTargets(txtName).setStyleAttribute("color", "red")
  .forTargets(lblRequiredName).setVisible(true)
  .setText('Please Enter Name')
  .setStyleAttribute("color", "red");

 btnSubmit.addClickHandler(serverHandler).addClickHandler(validateEmail).addClickHandler(validateName);
   app.add(panelMain);
  return app;
}

function Signup(thisForm)
{

  var app = UiApp.getActiveApplication();
  var txtName = thisForm.parameter.txtName;
  var txtEmail = thisForm.parameter.txtEmail;
  var lblStatus = thisForm.parameter.lblStatus;

  //Other code to save to data store
 ////
  app.getElementById("lblStatus").setText('Thanks for signing!');
  app.getElementById('gridMain').setVisible(false);

  return app;

 // return app2; //Everything is working fine right now 

}
4

1 回答 1

0

我不认为 validateEmail 过去是这样工作的。我在填写表格时是否可以为用户关闭自动填写中的解决方案?之前,我很确定它需要混合大小写。@Serge 可能记得。

问题 1799:谷歌应用程序脚本中的验证功能无法正常工作已报告,然后在 2012 年 9 月关闭,因为它过于广泛。我认为这为报告这个特定问题打开了大门。

对于自己进行电子邮件验证并处理混合大小写的替代方案,请查看此 Apps Script Tutorial on Email Validation

于 2013-01-19T02:06:58.950 回答