正则表达式验证中文、图片上传

验证中文

<script>
var str="这个字符串";
var reg=/^[u4e00-u9fa5]{0,}$/;
if(reg.exec(str))
alert('这个字符串有中文');
else
alert('这个字符串没有中文');
</script>

验证图片上传

var flag = true;

headPhotoFile = document.getElementById("headPhotoFile");

if(headPhotoFile){
if(!/.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(headPhotoFile)){
alert("图片类型必须是gif,jpeg,jpg,png中的一种");
flag = false;
}
}

原文地址:https://www.cnblogs.com/fengbing9891/p/5209779.html