2 * JavaScript for Special:ChangeEmail
7 * Given an email validity status (true, false, null) update the label CSS class
9 var updateMailValidityLabel = function( mail ) {
10 var isValid = mw.util.validateEmail( mail ),
11 $label = $( '#mw-emailaddress-validity' );
13 // We allow empty address
14 if( isValid === null ) {
15 $label.text( '' ).removeClass( 'valid invalid' );
18 } else if ( isValid ) {
19 $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
23 $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
27 $( document ).ready( function() {
28 // Lame tip to let user know if its email is valid. See bug 22449
29 // Only bind once for 'blur' so that the user can fill it in without errors
30 // After that look at every keypress for direct feedback if it was invalid onblur
31 $( '#wpNewEmail' ).one( 'blur', function() {
32 if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
33 $(this).after( '<label for="wpNewEmail" id="mw-emailaddress-validity"></label>' );
35 updateMailValidityLabel( $(this).val() );
36 $(this).keyup( function() {
37 updateMailValidityLabel( $(this).val() );
42 } )( jQuery, mediaWiki );