1 // ========================================================================== 2 // Project: SproutCore - JavaScript Application Framework 3 // Copyright: ©2006-2011 Strobe Inc. and contributors. 4 // Portions ©2008-2011 Apple Inc. All rights reserved. 5 // License: Licensed under MIT license (see license.js) 6 // ========================================================================== 7 8 sc_require('validators/validator') ; 9 10 /** 11 Requires a valid email format. 12 13 @class 14 @extends SC.Validator 15 @version 1.0 16 */ 17 SC.Validator.Email = SC.Validator.extend( 18 /** @scope SC.Validator.Email.prototype */ { 19 20 validate: function(form, field) { 21 return (field.get('fieldValue') || '').match(/.+@.+\...+/) ; 22 }, 23 24 validateError: function(form, field) { 25 var label = field.get('errorLabel') || 'Field' ; 26 return SC.$error(SC.String.loc("Invalid.Email(%@)", label), label) ; 27 } 28 29 }) ; 30 31 /** 32 This variant allows an empty field as well as an email address. 33 34 @class 35 @extends SC.Validator.Email 36 @author Charles Jolley 37 @version 1.0 38 */ 39 SC.Validator.EmailOrEmpty = SC.Validator.Email.extend( 40 /** @scope SC.Validator.EmailOrEmpty.prototype */ { 41 validate: function(form, field) { 42 var value = field.get('fieldValue') ; 43 return (value && value.length > 0) ? value.match(/.+@.+\...+/) : true ; 44 } 45 }) ; 46