 emailRe = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
 
 middleware =
-  isRequired: (value)->
+  isRequired: (value) ->
     return value if value && value != ''
 
     throw new Error 'Required'
 
-  isEmail: (value)->
-    if !value
-      return value
+  isEmail: (value) ->
+    return value unless value
 
     return value.toLowerCase() if emailRe.test value
 
     throw new Error 'Enter a valid email'
 
-  isNewPassword: (value)->
+  isNewPassword: (value) ->
     if !@get 'user.currentPassword'
       throw new Error 'Current password required' if value
       return value
 
     return middleware.isPassword value
 
-  isPassword: (value)->
-    if !value
+  isPassword: (value) ->
+    unless value
       throw new Error 'Required'
 
     return value if value.length >= 6

          reject new Error('Enter a valid card number')
        resolve value

  expiration: (value)->
    if !value
      return value

    if @('order.type') != 'stripe'
      return value


    throw new Error 'Passwords must match'

  splitName: (value) ->
    return value unless value

    parts     = value.trim().split ' '
    firstName = parts.shift()
    lastName  = parts.join ' '

    @set 'user.firstName', firstName
    @set 'user.lastName',  lastName

    value

  isEcardGiftRequired: (value) ->
    return value if (!@get('order.gift') || @get('order.giftType') != 'ecard') || (value && value != '')

    throw new Error 'Required'

  requiresStripe: (value) ->
    throw new Error "Required" if @('order.type') == 'stripe' && (!value? || value == '')
    return value

  requireTerms: (value) ->
    if !value
      throw new Error 'Please read and agree to the terms and conditions.'
    value

  cardNumber: (value) ->
    return value unless value

    if @('order.type') != 'stripe'
      return value
