2016-03-08 65 views
1

我想验证我的交互式PDF。所以,如果我点击一个按钮(用于验证)有下列背后代码:交互式PDF表单验证Javascript

var isBlank = false; 
var blank = "Please fill following fields:"; 
var isNotValid = false; 
var notValid = "Please check input data in following fields:"; 
var message = ""; 

var t = ['Division', 'Oragnisationseinheit', 'Name', 'KZZ', 'Privataddresse']; 
var i; 

for(var i=0; i<t.length;i++){ 
    //validation text fields needs to be filled in 
    if (this.getField(t[i]).value == "") { 
    blank = blank + "\n" + this.getField(t[i]).name; 
    isBlank = true; 
    } 

    //validation text field must contain only lower case letters 
    if (/^[a-z]*$/.test(this.getField(t[i]).value) == false) { 
    notValid = notValid + "\n" + this.getField(t[i]).name; 
    isNotValid = true; 
    } 

    //generate message 
    if (isBlank == true) { 
    message = blank + "\n" + "\n"; 
    } 
    if (isNotValid == true) { 
    message = message + notValid; 
    } 
} 
//check all conditions 
if ((isBlank == true) || (isNotValid == true)) { 
//show message 
app.alert({ cMsg: message, cTitle: "Input data error" }); 
} 

问题是现在,如果我按下按钮也没有反应。 - > var消息不会被显示。问题在哪里?

感谢您的所有想法。

回答

2

您可以尝试添加一个自定义验证脚本,该脚本首先会检查以确保该字段不是空白,如果不是,只需将输入更改为小写,以便用户无需自行修改该字段。

将以下代码添加到自定义字段验证脚本中。这应该适用于任何文本字段。

if (event.value.length == 0) { 
    app.alert({ cMsg: event.target.name + " cannot be blank.", cTitle: "Input data error" }); 
} 
else { 
    event.value = event.value.toLowerCase(); 
}