Common JavaScript function
//=========================================
Input data validation
Checking for null values
function Funcheckempty (m_text) {
var strtmp=m_text
if (strtmp = null | | strtmp = = "") {
return False
}
return True
}
Check the length of the content
function Funtextlencheck (m_text) {
var strtext=m_text
for (i=0;i<=strtext.length-1;i++) {
if (Strtext.charcodeat (i) >=256) {
Return Strtext.length * 2
}
}
Return strtext.length
}
Inspection length
function Funchecklen (m_len,m_text) {
if (Funtextlencheck (m_text) > M_len) {
return False
}
return True
}
Test is a number
function Funchecknumber (m_text) {
var strtmp=m_text
if (isNaN (strtmp)) {
return False
}
return True
}
Whether the date of inspection is legal
function Funcheckdate (m_year,m_month,m_day) {
Get the maximum date according to the month first
var maxday
if (m_month==2) {
Maxday=28
if (m_year% 4 ==0) {
maxday=29
}
} else {
if (m_month<=7) {
if (m_month% 2 ==0) {
Maxday=30
}else{
Maxday=31
}
}else{
if (m_month% 2 ==0) {
Maxday=31
}else{
Maxday=30
}
}
}
if (m_day>maxday) {
return False
}
return True
}
Read cookies information
function GetCookie (strcookname) {
var arvcookies=document.cookie.split (";")
for (var i=0;i< arvcookies.length; i++) {
var arvonecookie=arvcookies[i].split ("=")
if (Strcookname==arvonecookie[0]) {
Return unescape (Arvonecookie[1])
}
}
Return ""
}
To replace an illegal character in a string
function Replace_text (Text) {
var strtmp=text
Strtmp=strtmp.replace ("@", "@")
Strtmp=strtmp.replace ("?", "? ")
Strtmp=strtmp.replace ("&", "&")
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service