Created
January 14, 2012 16:08
-
-
Save tdegrunt/1611897 to your computer and use it in GitHub Desktop.
RegExp Validator for batman.js (RegExpValidator)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RegExpValidator extends Batman.Validator | |
@options 'with', 'message' | |
validateEach: (errors, record, key, callback) -> | |
value = record.get(key) | |
if !value? || !value.match(@options.with) | |
errors.add key, Batman.translate('errors.format', {attribute: key, message: @options.message}) | |
callback() | |
Batman.Validators.push RegExpValidator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use with: | |
@validate 'email', with: /^[\w-]+(.[\w-]+)@([a-z0-9-]+(.[a-z0-9-]+)?.[a-z]{2,6}|(\d{1,3}.){3}\d{1,3})(:\d{4})?$/, message: "must be a valid email address" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use with:
@Validate 'email', with: /^[\w-]+(.[\w-]+)@([a-z0-9-]+(.[a-z0-9-]+)?.[a-z]{2,6}|(\d{1,3}.){3}\d{1,3})(:\d{4})?$/, message: "must be a valid email address"