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

验证中文

<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;
}
}

posted @ 2016-02-23 14:21  张小屋  阅读(1321)  评论(0编辑  收藏  举报