Sha256: 965364c8ba25c19058d4d7c741bb2cfc05904a1dda8533ce81cdf71a90958a4f

Contents?: true

Size: 875 Bytes

Versions: 2

Compression:

Stored size: 875 Bytes

Contents

// ==========================================================================
// Email Validator
// Author: Charles Jolley
//
// Force a field to be an email address.
//
// ==========================================================================

require('validators/validator') ;
SC.Validator.Email = SC.Validator.extend({
  
  validate: function(form, field) { 
    return (field.get('fieldValue') || '').match(/.+@.+\...+/) ; 
  },
  
  validateError: function(form, field) {
    var label = field.get('errorLabel') || 'Field' ;
    return $error("Invalid.Email(%@)".loc(label), label) ;
  }  
    
}) ;

// this variant allows an email to be empty.
SC.Validator.EmailOrEmpty = SC.Validator.Email.extend({
  validate: function(form, field) {
    var value = field.get('fieldValue') ; 
    return (value && value.length > 0) ? value.match(/.+@.+\...+/) : true ;
  }
}) ;

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sproutcore-0.9.0 frameworks/sproutcore/validators/email.js
sproutcore-0.9.1 frameworks/sproutcore/validators/email.js