SoFunction
Updated on 2025-04-14

JavaScript tips  Super recommended page 2/5


Filter numbers
Copy the codeThe code is as follows:

<input type=text onkeypress="return >=48&&<=57||(('.')<0?==46:false)" onpaste="return !('text').match(/\D/)" ondragenter="return false"> 

//Special use
Copy the codeThe code is as follows:

<input type=button value=Import favorites onclick="(true,'http://localhost');">
<input type=button value=Export favorites onclick="(false,'http://localhost');">
<input type=button value=Organize favorites onclick="('OrganizeFavorites', null)">
<input type=button value=language settings   onclick="('LanguageDialog', null)">
<input type=button value=Add to favorites onclick="('/', 'google')">
<input type=button value=Add to channel onclick="('/')">
<input type=button value=Add to channel onclick="('PrivacySettings',null)">

No cache
Copy the codeThe code is as follows:

<META HTTP-EQUIV="pragma" CONTENT="no-cache"> 
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"> 
<META HTTP-EQUIV="expires" CONTENT="0"> 

Regular Match
Copy the codeThe code is as follows:

Regular expression matching Chinese characters: [\u4e00-\u9fa5]
Match double-byte characters (including Chinese characters): [^\x00-\xff]
Regular expression matching blank lines: \n[\s| ]*\r
Regular expression matching HTML tags: /<(.*)>.*<\/\1>|<(.*) \//
Regular expression matching the beginning and end spaces: (^\s*)|(\s*$) (trim function like vbscript)
Regular expression matching the email address: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Regular expression matching URL: http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
Here are examples:
Use regular expressions to restrict the input content of the text box in the web form:
Use regular expressions to restrict only Chinese: onkeyup="value=(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="('text',('text').replace(/[^\u4E00-\u9FA5]/g,''))"
1. Use regular expressions to limit only full-width characters to enter: onkeyup="value=(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="('text',('text').replace(/[^\uFF00-\uFFF]/g,''))"
2. Use regular expressions to limit only numbers to enter: onkeyup="value=(/[^\d]/g,'')"onbeforepaste="('text',('text').replace(/[^\d]/g,''))"
3. Use regular expressions to limit only numerical and English: onkeyup="value=(/[\W]/g,'')"onbeforepaste="('text',('text').replace(/[^\d]/g,''))"

Eliminate the image toolbar
Copy the codeThe code is as follows:

<IMG SRC="" HEIGHT="100px" WIDTH="100px" GALLERYIMG="false">   or 
<head> 
<meta http-equiv="imagetoolbar" content="no"> 
</head> 

Previous page12345Next pageRead the full text