![](/img/trans.png)
[英]difference between a javascript and regular expression and filter_var for email validation
[英]Form validation using filter_var
我正在使用JavaScript進行作業。 我正在嘗試使用filter_var來測試我的表單是否具有空字段,但無法使其運行。
我不確定我的語法是否正確。
function validate_reg_form(form)
{
var form = "";
if (filter_var(form, FILTER_VALIDATE_BOOLEAN))
{
alert("validate_reg_form() not yet implemented");//remove this
}
}
filter_var
是一個PHP函數 。 它在JavaScript中不存在。 確切的等效項是:
var truthyBooleanStrings = ['1', 'true', 'on', 'yes'];
function validateRegForm(form) {
var form = '';
if (truthyBooleanStrings.indexOf(form) !== -1) {
// …
}
}
也許這不是正確的方法
測試我的表單是否有空字段
不過。 如果要測試某個東西不是空字符串,只需使用!== ''
或非空字符串的隱式真實性,如
if (form) {
// Not empty!
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.