<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-5  評論-41  文章-13  trackbacks-0
    初步實現(xiàn)。

    ??1?<!--
    ??2?????/**********************************************************
    ??3??????*?validatorUtil.js
    ??4??????*?@author?lightning
    ??5??????*?@version?0.1
    ??6??????*?使用javascript的prototype特性對String等對象進行擴展
    ??7??????*?建立一個輸入交驗的基本工具。由于實現(xiàn)中大量的使用了正則表達式,
    ??8??????*?需要修改源碼的朋友請先自己復(fù)習一下javascript的正則表達式
    ??9??????*?
    ?10??????**********************************************************/
    ?11?
    ?12?????/**
    ?13??????*?此處選擇對String進行擴展主要是因為javascript與html,jsp等頁面
    ?14??????*?進行交互的過程中,主要的數(shù)據(jù)類型是String(javascript取得的頁面數(shù)據(jù),基本上默認都是String類型)。
    ?15??????*?即使要使用別的數(shù)據(jù)類型,也可以和String很方便的進行轉(zhuǎn)化。
    ?16??????*/
    ?17?????String.prototype.trim?=?trim;
    ?18?????String.prototype.isEmpty?=isEmpty;
    ?19?????String.prototype.isEmail=isEmail;
    ?20?????String.prototype.isIP=isIP;
    ?21?????String.prototype.isNumber=isNumber;
    ?22?????String.prototype.isEnglish=isEnglish;
    ?23?????String.prototype.isChinese=isChinese;
    ?24?????String.prototype.hasChinese=hasChinese;
    ?25?????String.prototype.isIntBetween=isIntBetween;
    ?26?????String.prototype.byteLength=byteLength;
    ?27?????
    ?28?????/**
    ?29??????*?$
    ?30??????*?@param?{String}?id
    ?31??????*?@return?{Element}?返回具有指定id的Element對象
    ?32??????*/
    ?33?????function?$(id)?{
    ?34?????????var?element;
    ?35?????????if?(typeof?id?==?'string'){
    ?36???????????element?=?document.getElementById(id);
    ?37?????????}
    ?38???????????
    ?39?//每取得一個element都對其進行這樣子的方法添加開銷可能會很大,不太現(xiàn)實??????????
    ?40?//??????????element.trim?=?trim;
    ?41?//??????????element.isEmpty?=isEmpty;
    ?42?//??????????element.isEmail=isEmail;
    ?43?//??????????element.isIP=isIP;
    ?44?//??????????element.isNumber=isNumber;
    ?45?//??????????element.isEnglish=isEnglish;
    ?46?//??????????element.isChinese=isChinese;
    ?47?//??????????element.hasChinese=hasChinese;
    ?48?//??????????element.isIntBetween=isIntBetween;
    ?49?//??????????element.byteLength=byteLength;
    ?50??????
    ?51?????????return?element;
    ?52?????}
    ?53?????
    ?54?????/**
    ?55??????*?$$
    ?56??????*?@param?{String}?id?
    ?57??????*?@return?{String}?id等于param的element的值
    ?58??????*/
    ?59?????function?$$(id)?{
    ?60?????????var?elementValue="";
    ?61?????????if?(typeof?id?==?'string'){
    ?62???????????elementValue?=?document.getElementById(id).value;
    ?63?????????}
    ?64?????????return?elementValue;
    ?65?????}
    ?66?????
    ?67?????/**
    ?68??????*?$A
    ?69??????*?<p>
    ?70??????*?????此方法最基本的使用是方便地取得指定id的element的指定attribute。
    ?71??????*??可以對此進行一些擴展使用。
    ?72??????*??如:在element中增加自定義的attribute--"errorMsg",
    ?73??????*?????用于保存一些固定的提示信息(可以和一些框架標簽結(jié)合使用實現(xiàn)提示信息的國際化)
    ?74??????*?????這樣就可以使用javascript方便地顯示這些信息
    ?75??????*?<p>
    ?76??????*?@param?{String}?id?element的id值
    ?77??????*?@param?{String}?attName?所要取得的attribute的名稱
    ?78??????*?@return?Attribute?返回所指定的Attribute的內(nèi)容
    ?79??????*/
    ?80?????function?$A(?id,?attName?){
    ?81?????????return?document.getElementById(id).getAttribute(attName);
    ?82?????}
    ?83?????
    ?84?????/**
    ?85??????*?$N
    ?86??????*?@param?{String}?elementName?所要取得的element的名稱
    ?87??????*?@return?{Element}?返回具有指定名稱的Element對象數(shù)組
    ?88??????*/
    ?89?????function?$N(elementName){
    ?90?????????return?document.getElementsByName(elementName);
    ?91?????}
    ?92?????
    ?93?????/**
    ?94??????*?$Tag
    ?95??????*?@param?{String}?tagName?所要取得的tag的名稱
    ?96??????*?@return?{Element}?返回具有指定tag名(element類型)的Element對象數(shù)組
    ?97??????*/
    ?98?????function?$Tag(tagName){
    ?99?????????return?document.getElementsByTagName(tagName);
    100?????}
    101?????
    102?????/**
    103??????*?trim
    104??????*?@return?{String}?去掉頭尾空白符的字符串
    105??????*/
    106?????function?trim(){
    107?????????return?this.replace(/(^\s*)|(\s*$)/g,?"");
    108?????}
    109??????/**
    110???????*?isEmpty
    111???????*?@return?{Boolean}?判斷對象的值是否為空
    112???????*/
    113?????function?isEmpty(){
    114?????????if(this.trim()==""){
    115?????????????return?true;
    116?????????}
    117?????????return?false;
    118?????}
    119?????/**
    120??????*?isEmail
    121??????*?@return?{Boolean}?對象的值是否符合email的格式
    122??????*/
    123?????function?isEmail(){
    124?????????var?EmailReg=/\w+@(\w+\.)+[a-z]{2,3}/g;
    125?????????if(this.trim().search(EmailReg)!=-1){
    126?????????????return?true;
    127?????????}
    128?????????return?false;
    129?????}
    130?????/**
    131??????*?isIP
    132??????*?@return?{Boolean}?對象的值是否符合IP的格式
    133??????*/
    134?????function?isIP()?{
    135?????????var?ipReg=/^(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])$/g;
    136?????????if(this.trim().search(ipReg)!=-1){
    137?????????????return?true;
    138?????????}
    139?????????return?false;
    140?????}
    141?????/**
    142??????*?isNumber
    143??????*?@return?{Boolean}?Element的類型是否為Number
    144??????*/
    145??????function?isNumber()?{
    146??????????var?nuReg=/^\d+$/g;
    147?????????if(this.trim().search(nuReg)!=-1){
    148?????????????return?true;
    149?????????}
    150?????????return?false;
    151??????}
    152?????/**
    153??????*?isEnglish
    154??????*?@return?{Boolean}?Element的值是否為英文(全部是英文字母)
    155??????*/
    156??????function?isEnglish()?{
    157?????????var?enReg=/^[A-Za-z]+$/g;
    158?????????if(this.trim().search(enReg)!=-1){
    159?????????????return?true;
    160?????????}
    161?????????return?false;
    162??????}
    163?????/**
    164??????*?isChinese
    165??????*?@return?{Boolean}?Element的值是否為中文(全部是中文字符)
    166??????*/
    167?????function?isChinese()?{
    168?????????var?chReg=/^[\u0391-\uFFE5]+$/g;
    169?????????if(this.trim().search(chReg)!=-1){
    170?????????????return?true;
    171?????????}
    172?????????return?false;
    173?????}
    174?????/**
    175??????*?hasChinese
    176??????*?@return?{Boolean}?Element是否包含有中文字符
    177??????*/
    178?????function?hasChinese()?{
    179?????????var?chReg=/[\u0391-\uFFE5]+/g;
    180?????????if(this.trim().search(chReg)!=-1){
    181?????????????return?true;
    182?????????}
    183?????????return?false;
    184?????}
    185?????/**
    186??????*?numBetween
    187??????*?@param?{Number}?max?
    188??????*?@param?{Number}?min
    189??????*?@return?{Boolean}?Element的值是否大于min小于max
    190??????*/
    191??????function?isIntBetween(max,min)?{
    192??????????min?=?min?||?0;
    193?????????max?=?max?||?Number.MAX_VALUE;
    194?????????return?min?<=?parseInt(this)?&&?parseInt(this)?<=?max;
    195??????}
    196??????/**
    197???????*?byteLength
    198???????*?@return?number?InputElemen的值所含字節(jié)數(shù)(雙字節(jié)字符算兩個)
    199???????*/
    200???????function?byteLength()?{
    201???????????return?this.replace(/[^\x00-\xff]/g,"**").length;
    202???????}
    203???????
    204???????/***********************************
    205????????*?下面的這幾個是從spring嘟嘟的嘟嘟老窩里取得的
    206????????*?還沒有經(jīng)過整理,只供參考。大家要用的話可以自己進行整理。
    207????????*?和筆者的實現(xiàn)不同,嘟嘟的這些方法中使用最多的實現(xiàn)方式是
    208????????*?typeof和constructor
    209????????***********************************/
    210?//????function?isAlien(a)?{
    211?//??????return?isObject(a)?&&?typeof?a.constructor?!=?'function';
    212?//????}
    213?//????
    214?//?????
    215?//????
    216?//????function?isArray(a)?{
    217?//??????return?isObject(a)?&&?a.constructor?==?Array;
    218?//????}
    219?//????
    220?//????function?isBoolean(a)?{
    221?//??????return?typeof?a?==?'boolean';
    222?//????}
    223?//????
    224?//????function?isEmpty(o)?{
    225?//??????var?i,?v;
    226?//??????if?(isObject(o))?{
    227?//????????for?(i?in?o)?{
    228?//??????????v?=?o[i];
    229?//??????????if?(isUndefined(v)?&&?isFunction(v))?{
    230?//????????????return?false;
    231?//??????????}
    232?//????????}
    233?//??????}
    234?//??????return?true;
    235?//????}
    236?//
    237?//????function?isFunction(a)?{
    238?//??????return?typeof?a?==?'function';
    239?//????}
    240?//????
    241?//????function?isNull(a)?{
    242?//??????return?typeof?a?==?'object'?&&?!a;
    243?//????}
    244?//????
    245?//????function?isNumber(a)?{
    246?//??????return?typeof?a?==?'number'?&&?isFinite(a);
    247?//????}
    248?//????
    249?//????function?isObject(a)?{
    250?//??????return?(a?&&?typeof?a?==?'object')?||?isFunction(a);
    251?//????}
    252?//????
    253?//????function?isString(a)?{
    254?//??????return?typeof?a?==?'string';
    255?//????}
    256?//????
    257?//????function?isUndefined(a)?{
    258?//??????return?typeof?a?==?'undefined';
    259?//????}
    260?//-->

    posted on 2006-05-10 16:50 OO 閱讀(385) 評論(0)  編輯  收藏 所屬分類: java相關(guān)的亂七八糟的東西
    主站蜘蛛池模板: 久久青青草原亚洲AV无码麻豆| 在线观看AV片永久免费| 久久精品国产精品亚洲色婷婷| AV激情亚洲男人的天堂国语| 亚洲一区视频在线播放| 无人在线观看免费高清| 亚洲精品亚洲人成在线| 亚洲午夜爱爱香蕉片| 毛片免费全部播放无码| 女人裸身j部免费视频无遮挡| 国产免费怕怕免费视频观看| 黄色片免费在线观看| 亚洲另类无码专区丝袜| 国产成人亚洲综合无码精品| 日韩免费视频一区| 国产成人啪精品视频免费网| 免费无码又爽又刺激一高潮| 丰满亚洲大尺度无码无码专线| 日韩精品视频免费在线观看| 99精品视频在线观看免费| 亚洲精品久久久久无码AV片软件| 日韩伦理片电影在线免费观看| 亚洲欧美日韩中文高清www777| 成年女人看片免费视频播放器| 亚洲人成色4444在线观看| 亚洲αv在线精品糸列| 国产一级高清免费观看| 亚洲视频在线观看免费视频| 中文字幕手机在线免费看电影| 国产AV无码专区亚洲AV男同| 十八禁无码免费网站| 日韩电影免费在线观看网址| 中文字幕亚洲综合小综合在线 | 国产免费AV片在线观看| 色婷婷六月亚洲综合香蕉| 亚洲日本在线播放| 亚洲福利在线视频| 99热免费在线观看| 国产人成网在线播放VA免费| 亚洲熟妇AV日韩熟妇在线| 亚洲综合久久1区2区3区|