您好,欢迎来到源码搜藏!分享精神,快乐你我!提示:担心找不到本站?在百度搜索“源码搜藏”,网址永远不丢失!
  • 首 页
  • 在线工具
  • 当前位置:首页 > 网页特效 > jQuery特效 >

    jQuery邮件地址验证插件

    时间:2014-06-18 08:19 来源:互联网 作者:源码搜藏 浏览:收藏 挑错 推荐 打印

    效果预览 进入下载地址列表
    jQuery邮件地址验证插件jQuery邮件地址验证插件是一款jQuery addClassWhenEmail插件。jQuery表单邮件验证jQuery插件

    <script src="js/main.js"></script>
    <script>
     
    ;( function( window, document, undefined )
    {
    'use strict';
     
    var form = '.newsletter',
    className = 'newsletter--active',
    email = 'input[type="email"]',
     
    addEventListener = function( element, event, handler )
    {
    element.addEventListener ? element.addEventListener( event, handler 
     
    ) : element.attachEvent( 'on' + event, function(){ handler.call( element ); });
    },
    forEach = function( elements, fn )
    {
    for( var i = 0; i < elements.length; i++ ) fn( elements[ i ], i );
    },
    addClass = function( element, className )
    {
    element.classList ? element.classList.add( className ) : 
     
    element.className += ' ' + className;
    },
    removeClass = function( element, className )
    {
    element.classList ? element.classList.remove( className ) : 
     
    element.className += element.className.replace( new RegExp( '(^|\\b)' + className.split( ' 
     
    ' ).join( '|' ) + '(\\b|$)', 'gi' ), ' ' );
    };
     
    forEach( document.querySelectorAll( form ), function( $form )
    {
    var $email = $form.querySelectorAll( email );
     
    if( $email.length )
    {
    $email = $email[ 0 ];
    addEventListener( $email, 'keyup', function()
    {
    $email.value != '' && /^([\w-\.]+@([\w-]+\.)+[\w-]{2,12})?
     
    $/.test( $email.value ) ? addClass( $form, className ) : removeClass( $form, className );
    });
    }
    });
    })( window, document );
     
    /*
     
    jQuery version:
     
    $( function( $, window, document, undefined )
    {
    'use strict';
     
    var form = '.newsletter',
    className = 'newsletter--active',
    email = 'input[type="email"]';
     
    $( form ).each( function()
    {
    var $form = $( this ),
    $email = $form.find( email );
     
    $email.on( 'keyup.addClassWhenEmail', function()
    {
    $form.toggleClass( className, $email.val() != '' && /^([\w-\.]+@
     
    ([\w-]+\.)+[\w-]{2,12})?$/.test( $email.val() ) );
    });
    });
    })( jQuery, window, document );
     
    */
     
    </script>
    jQuery邮件地址验证插件由源码搜藏网整理,转载请注明出处http://www.codesocang.com/texiao/jQuerytexiao/9534.html 源码搜藏承诺:本站所有资源无病毒,无弹窗,无干扰链接!