blossom
Version:
Modern, Cross-Platform Application Framework
46 lines (37 loc) • 1.33 kB
JavaScript
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
// Portions ©2008-2010 Apple Inc. All rights reserved.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
sc_require('validators/validator') ;
/**
Requires a valid email format.
@class
@extends SC.Validator
@version 1.0
*/
SC.Validator.Email = SC.Validator.extend(
/** @scope SC.Validator.Email.prototype */ {
validate: function(form, field) {
return (field.get('fieldValue') || '').match(/.+@.+\...+/) ;
},
validateError: function(form, field) {
var label = field.get('errorLabel') || 'Field' ;
return SC.$error("Invalid.Email(%@)".loc(label), label) ;
}
}) ;
/**
This variant allows an empty field as well as an email address.
@class
@extends SC.Validator.Email
@author Charles Jolley
@version 1.0
*/
SC.Validator.EmailOrEmpty = SC.Validator.Email.extend(
/** @scope SC.Validator.EmailOrEmpty.prototype */ {
validate: function(form, field) {
var value = field.get('fieldValue') ;
return (value && value.length > 0) ? value.match(/.+@.+\...+/) : true ;
}
}) ;