乱七八糟

代码
$.fn.ltrim=function(val){
return val.replace(/(^\s*)/,"");
}

$.fn.rtrim
=function(val){
return val.replace(/(\s*$)/g,"");
}

$.fn.trim
=function(val){
return val.replace(/(^\s*)|(\s*$)/g, "");
}

$.fn.isInt
=function(val){
val
=$(this).trim(val);
var b
=false;
if(val==""){
returnfalse;
}
var num
=/^[0-9]{1,}$/;

return num.test(val);
}


$.fn.isStr
=function(str){

var s
=/^[0-9][a-z][A-Z]$/;
return s.test(str);
}

$.fn.isComp
=function(a,b){
return a==b;
}



$.fn.isChinese
=function(name){
if(name.length==0){

returnfalse;
}

for(i=0;i<name.length;i++){

if(name.charAt(i)>128){
returntrue;
}
}
returnfalse;
}
$.fn.isEmail
=function(val){
var email
=/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/;

return email.test(val);
}

$.fn.UserName
=function(val){
val
=$(this).trim(val);
var username
=/^w{6,16}$/;
return username.test(val);


}

$.fn.password
=function(val){
//验证用户密码
var p=/^[a-zA-Z0-9]{5,17}$/;
return p.test(val);

}

 

博客园  评论 JS

/*    博客园留言板JS   #region UBB */
$.fn.extend({
    selection: function () {
        var txt = '';
        var doc = this.get(0).document;
        if (doc) {
            var sel = doc.selection.createRange();
            if (sel.text.length > 0)
                txt = sel.text;
        }
        else if (this.get(0).selectionStart || this.get(0).selectionStart == '0') {
            var s = this.get(0).selectionStart;
            var e = this.get(0).selectionEnd;
            if (s != e) {
                txt = this.get(0).value.substring(s, e);
            }
        }
        return $.trim(txt);
    },
    parseHtml: function (t) {
        var doc = this.get(0).document;
        if (doc) {
            this.get(0).focus();
            doc.selection.createRange().collapse;
            this.get(0).document.selection.createRange().text = t;
        }
        else if (this.get(0).selectionStart || this.get(0).selectionStart == '0') {
            var s = this.get(0).selectionStart;
            var e = this.get(0).selectionEnd;
            var val = this.get(0).value;
            var start = val.substring(0, s);
            var end = val.substring(e);
            this.get(0).value = start + t + end;
        }
    }
})
var insertUBB = function (id, html) {
    var val = $('#' + id).selection();
    if (val == '') {
        alert('请选择文字');
    }
    else {
        var end = html;
        if (html.indexOf('=') >= 0)
            end = html.substring(0, html.indexOf('='));
        $('#' + id).parseHtml('[' + html + ']' + val + '[/' + end + ']');
    }
}
function insertIndent(id) {
    var val = $('#' + id).selection();
    if (val == '') {
        $('#' + id).parseHtml("  ");
    }
    else {
        $('#' + id).parseHtml("  " + val);
    }
}
function insertUbbUrl(id) {
    var p1 = prompt("显示链接的文本.\n如果为空,那么将只显示超级链接地址", "");
    if (p1 != null) {
        var p2 = prompt("http:// 超级链接", "http://");
        if (p2 != '' && p2 != 'http://') {
            if (p1 != '') {
                $('#' + id).parseHtml('[url=' + p2 + ']' + p1 + '[/url]');
            }
            else {
                $('#' + id).parseHtml('[url]' + p2 + '[/url]');
            }
        }
    }
}
function insertUbbImg(id) {
    var p = prompt('请先将图片上传到您的图库中,然后将图片地址拷下粘贴在此:', 'http://');
    if (p == null || $.trim(p) == '' || p.toLowerCase() == 'http://')
        return;
    $('#' + id).parseHtml('[img]' + p + '[/img]');
}
function insertUploadImg(imgUrl) {
    $('#tbCommentBody').parseHtml('[img]' + imgUrl + '[/img]\n');
    $('#tbCommentBody').focus();
}
function insertUbbCode() {
    var c_width = 450;
    var c_height = 400;
    var leftVal = (screen.width - c_width) / 2;
    var topVal = (screen.height - c_height) / 2;
    var codeWindow = window.open('/SyntaxHighlighter.htm', '_blank', 'width=' + c_width + ',height=' + c_height + ',toolbars=0,resizable=1,left=' + leftVal + ',top=' + topVal);
    codeWindow.focus();
}
/* #endregion */

 

 

 

posted @ 2010-11-04 22:53  Rhythmk  阅读(1216)  评论(64编辑  收藏  举报
Rhythmk 个人笔记