1.验证手机号? 15010291464
?
?$.validator.methods.tel = function(value, element, param){
?? ??var tel = /^(130|131|132|133|134|135|136|137|138|139|150|153|157|158|159|180|187|188|189)\d{8}$/;
??? if(param==true){
??? ?
??? if(!tel.exec(value)){
??? ?return false;
??? }else{
??? ?return true;
??? }
}};
?
?
2.验证下拉菜单 是否选择
?
请先设置<option value="-1 ">请选择</option>值为-1,
?
$.validator.methods.selectOption = function(value, element, param){
???
? if(param==true){
???? if(value!=null&&value!=-1 ){
?????? return true;
???? }
???????
}};
?
?
?
3.验证ip地址是否正确??
$.validator.methods.ip = function(value, element, param){
??? //在这里使用上面的三个参数进行校验
??? if(param==true){
??? if(this.optional(element) || (/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.test(value) && (RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256))){
????? return true;
??? }
???????
}};
?
?
4.统计判断当前用户输入的字节数以区分汉字和字母(验证不超过32个字节)
$.validator.methods.getByteCount = function(value, element, param){
??
??? ? if(param==true){
??? ? ???
??? ??? ?
??? ??? var len = 0;
??? ??? for(var i = 0; i < value.length; i++) {
??? ??? ??? if(value.charCodeAt(i) > 0xFF) { //非英文字符
??? ??? ??? ??? len += 2;
??? ??? ??? } else {
??? ??? ??? ??? len ++;
??? ??? ??? }
??? ??? }
??? ???
??? ??? if(len>32){
??? ??? ???
??? ??? ??? return false;
??? ??? }else{
??? ??? ??? return true;
??? ??? }
????
???????
}};
?
?
5.验证radio是否选择了
?$.validator.methods.radio = function(value, element, param){
??? //得到radio的值
??? var item = $('input[name=snatUdpMode][checked]').val();
? if(param==true){
???? if(item!=undefined){
?????? return true;
???? }
???????
}};
?
?
6.其他
var reg=/^[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}$/;?????????? //XX:XX:XX:XX:XX:XX
?
?
?var reg=/^[0-9]{1,}\.[0-9]{1,}$/;???? //1.7?? 0-9之间的数字和.?????????? .在这里使用了转义符