【发布时间】:2021-11-11 20:48:48
【问题描述】:
我正在开发一个小项目,我目前正在尝试在 php 中使用 JQuery 验证注册表单。问题是我无法找出图像格式的正确正则表达式。验证函数:
function validateRegisterForm(event) {
event.preventDefault();
var photo=$("#profphoto")[0].files;
var photo_pattern = /\.(?:jpeg|jpg|gif)$/
if (!photo_pattern.test(photo)) {
if (isEmpty(photo)) {
$("#error_photo").text("Photo can not be empty");
$("#profphoto").focus();
return;
}else{
$("#error_photo").text("Upload format is not correct");
$( "#profphoto" ).focus();
return;
}
}else {
$("#error_photo").text("");
}
}
我还有其他字段,如姓名、姓氏等,但它们工作得很好,这就是为什么不包括在内。请帮忙!
【问题讨论】:
标签: jquery validation file-upload frontend