常用ASP+VBSCRIPT判斷函數

來源:互聯網
上載者:User

Function IsValidQQNumber(QQString)
'判斷QQ號碼格式
IsValidQQNumber=True

if Len(QQString)<5 or Len(QQString)>12 then
IsValidQQNumber=False
else
for i = 1 to Len(QQString)
   testchar = Lcase(Mid(QQString, i, 1))
   if not IsNumeric(testchar) then
         IsValidQQNumber = false
         exit Function
       end if
    next
next
end if

End Function

Function IsValidTelNumber(strTelephone)
'判斷電話號碼格式
IsValidTelNumber = True
  if Len(strTelephone) <= 0 then
    IsValidTelNumber = false
    exit Function
  end if
 
  if Left(strTelephone, 1) = "-" or Right(strTelephone, 1) = "-" then
       IsValidTelNumber = false
       exit Function
  end if
 
  for i = 1 to Len(strTelephone)
      testchar = Mid(strTelephone, i, 1)
   if testchar<>"-" then
    if not IsNumeric(testchar) then
         IsValidTelNumber = false
         exit Function
      end if
   end if 
  next

end Function

Function IsValidMobileNumber(strMobile)
'判斷手機號碼格式
IsValidMobileNumber = True
  if Len(strMobile) <= 0 then
    IsValidMobileNumber = false
    exit Function
  else
   if Len(strMobile) >13 then
    IsValidMobileNumber = false
    exit Function
   end if  
  end if
  
  for i = 1 to Len(strMobile)
      testchar = Mid(strMobile, i, 1)
    if not IsNumeric(testchar) then
         IsValidMobileNumber = false
         exit Function
      end if
  next

end Function

Function IsValidEmail(email)
'判斷電子郵件格式
IsValidEmail = true
emailstr = Split(email, "@")
if UBound(emailstr) <> 1 then
    IsValidEmail = false
    exit Function
end if

for each emailchr in emailstr
  if Len(emailchr) <= 0 then
   IsValidEmail = false
      exit Function
  end if
  for i = 1 to Len(emailchr)
      testchar = Lcase(Mid(emailchr, i, 1))
   if InStr("abcdefghijklmnopqrstuvwxyz_-.", testchar) <= 0 and not IsNumeric(testchar) then
   '如果不是字元允許的字母則必須是數字
         IsValidEmail = false
         exit Function
       end if
    next
 '如果是允許的字元,則必須包含小數點
 if Left(emailchr, 1) = "." or Right(emailchr, 1) = "." then
       IsValidEmail = false
       exit Function
    end if
next

if InStr(emailstr(1), ".") <= 0 then
  IsValidEmail = false
    exit Function
end if
i = Len(emailstr(1)) - InStrRev(emailstr(1), ".")
if i <> 2 and i <> 3 then
    IsValidEmail = false
    exit Function
end if
if InStr(email, "..") > 0 then
    IsValidEmail = false
end if
end Function 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.