惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Security Latest
Security Latest
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
NISL@THU
NISL@THU
T
Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
J
Java Code Geeks
P
Privacy International News Feed
阮一峰的网络日志
阮一峰的网络日志
S
Schneier on Security
博客园 - 聂微东
Project Zero
Project Zero
美团技术团队
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Scott Helme
Scott Helme
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 司徒正美
O
OpenAI News
Last Week in AI
Last Week in AI
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
SecWiki News
SecWiki News
月光博客
月光博客
S
Security Affairs
The GitHub Blog
The GitHub Blog
P
Privacy & Cybersecurity Law Blog
S
Secure Thoughts
V
V2EX
S
Securelist
F
Fortinet All Blogs
W
WeLiveSecurity
D
Docker
博客园 - 三生石上(FineUI控件)
Simon Willison's Weblog
Simon Willison's Weblog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Visual Studio Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Engineering at Meta
Engineering at Meta

博客园 - 才君

滚木头 中国身份证号码验证,支持15,18位 ErrorLog日志记录类 C#操作ini文件类 C#操作ini文件类 C#操作ini文件类 程序员——好好规划自己的路 程序员——好好规划自己的路 C#操作ini文件类 C#中的大小写约定 C#中的大小写约定 C#中的大小写约定 C#中的大小写约定 C#中的大小写约定 程序员——好好规划自己的路 C#只允许启动一个WinFrom进程 C#只允许启动一个WinFrom进程 滚木头 滚木头 C#操作ini文件类 程序员——好好规划自己的路 C#中的大小写约定 C#中的大小写约定 C#中的大小写约定 程序员——好好规划自己的路 程序员——好好规划自己的路
js中String的常用扩展
才君 · 2010-08-31 · via 博客园 - 才君

js中String的常用扩展,包括trim,检查中文,url,emal,电话号码,转类型,格式化代码等

//去掉字符串空间调用方式 字符串.trim()     
String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, "");}         
   
//求字符穿真实长度汉字2个字节 字符串.lengthw()     
String.prototype.lengthW = function(){ return this.replace(/[^\x00-\xff]/g,"**").length;}     
   
//判断是否email     
String.prototype.isEmail = function(){ return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this);}     
   
// 字符串中是否包含中文     
String.prototype.existChinese = function(){return /^[\x00-\xff]*$/.test(this);}       
   
//检查url       
String.prototype.isUrl = function(){ return /^http[s]?:\/\/([\w-]+\.)+[\w-]+([\w-./?%&=]*)?$/i.test(this);}     
   
//检查电话号码     
String.prototype.isPhoneCall = function(){ return /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(this);}     
   
//检查整数     
String.prototype.isNumber=function(){return /^[0-9]+$/.test(this);}     
   
// 整数转换     
String.prototype.toNumber = function(def){return isNaN(parseInt(this, 10)) ? def : parseInt(this, 10);}       
   
// 小数转换     
String.prototype.toMoney = function(def){return isNaN(parseFloat(this)) ? def : parseFloat(this);}   
 
//格式化代码 
String.prototype.format = function() { 
    var args = arguments; 
    return this.replace(/{(\d{1})}/g, function() { 
        return args[arguments[1]]; 
    }); 
};