検証用の正規表現(JS)
//
function isDigit(s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
// : 5-20 、 、“_”、“.”
function isRegisterUserName(s)
{
var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
if (!patrn.exec(s)) return false
return true
}
// : 1-30
function isTrueName(s)
{
var patrn=/^[a-zA-Z]{1,30}$/;
if (!patrn.exec(s)) return false
return true
}
// : 6-20 、 、
function isPasswd(s)
{
var patrn=/^(\w){6,20}$/;
if (!patrn.exec(s)) return false
return true
}
// 、 : “+” , , “-”
function isTel(s)
{
//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
// : , , “-”
function isMobil(s)
{
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
//
function isPostalCode(s)
{
//var patrn=/^[a-zA-Z0-9]{3,12}$/;
var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
if (!patrn.exec(s)) return false
return true
}
// IP
function isIP(s) //by zergling
{
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
//
function isSearch(s)
{
var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;
if (!patrn.exec(s)) return false
return true
}
//
function checkID(id){
var idNum = id;
//alert(idNum);
var errors=new Array(
" ",
" ",
" ",
" ",
" "
);
//
var re;
var len = idNum.length;
//
if(len != 15 && len != 18){
return errors[1];
}else if(len == 15){
re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
}else{
re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})([0-9xX])$/);
}
var area={11:" ",12:" ",13:" ",14:" ",
15:" ",21:" ",22:" ",23:" ",31:" ",
32:" ",33:" ",34:" ",35:" ",36:" ",
37:" ",41:" ",42:" ",43:" ",44:" ",
45:" ",46:" ",50:" ",51:" ",52:" ",
53:" ",54:" ",61:" ",62:" ",63:" ",
64:" ",65:" ",71:" ",81:" ",82:" ",
91:" "}
var idcard_array = new Array();
idcard_array = idNum.split("");
//
if(area[parseInt(idNum.substr(0,2))]==null) {
return errors[4];
}
//
var a = idNum.match(re);
if (a != null){
if (len==15){
var DD = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var flag = DD.getYear()==a[3]&&(DD.getMonth()+1)==a[4]&&DD.getDate()==a[5];
}
else if(len == 18){
var DD = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var flag = DD.getFullYear()==a[3]&&(DD.getMonth()+1)==a[4]&&DD.getDate()==a[5];
}
if (!flag) {
return " !";
}
//
if(len == 18){
S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
+ parseInt(idcard_array[7]) * 1
+ parseInt(idcard_array[8]) * 6
+ parseInt(idcard_array[9]) * 3 ;
Y = S % 11;
M = "F";
JYM = "10X98765432";
M = JYM.substr(Y,1);//
// ID
if(M == idcard_array[17]){
return "";
}
else{
return errors[3];
}
}
}else{
return errors[2];
}
return "";
}
「^\d+$」//負の整数ではない(正の整数+0)"^[0-9]*[0-9]*///正の整数"^(-\\d+)(((+))///正の整数ではない(^-[0-9]*[1-9]][0-9]]]*///////““““?????????????????????????????""""/“““““+浮整数"""""""""""""""""""/""""""/"/"/"/"/"""""/"/"""""/"/"/"/"""/*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)𞓜([0-9]]*[[1-9]][0-9]]]]]]]]“//正浮動小数点数"""""""//"""""""///"""""""""""""""/""""""/"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""(((([[[[0-0-9""""""""""""""""""""""「/負浮動小数点数」^(-?\d+)(\\\\\d+)"/浮動小数点数"^[A-Za-z]+"//26文字のアルファベットで構成された文字列「^[A-Z]+$」//26文字の大文字で構成された文字列「^[a-z]+」//26文字の小文字で構成された文字列「^[A-Za-z 0-9]+$」/////数字と26文字のアルファベットで構成された文字列「\\w+」/数字、26文字、アルファベットまたはアンダースコアの文字列で構成されている文字列「\\\\\\\\\\\\\\\"[\\w-]+(\\\\\\d+)?|(0+(\.0+)$'/emailアドレス)^[a-zA-z]+:/(\\\\\d+)'/url)^[A-Za-z 0-9_]*"