1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-30 11:24:21 +01:00
fab-manager/app/assets/javascripts/directives/validators.coffee

34 lines
896 B
CoffeeScript
Raw Normal View History

2016-03-23 18:39:41 +01:00
'use strict'
Application.Directives.directive 'url', [ ->
URL_REGEXP = /^(https?:\/\/)([\da-z\.-]+)\.([-a-z0-9\.]{2,30})([\/\w \.-]*)*\/?$/
{
require: 'ngModel'
link: (scope, element, attributes, ctrl) ->
ctrl.$validators.url = (modelValue, viewValue) ->
if ctrl.$isEmpty(modelValue)
return true
if URL_REGEXP.test(viewValue)
return true
# otherwise, this is invalid
return false
}
]
Application.Directives.directive 'endpoint', [ ->
ENDPOINT_REGEXP = /^\/([-._~:?#\[\]@!$&'()*+,;=%\w]+\/?)*$/
{
require: 'ngModel'
link: (scope, element, attributes, ctrl) ->
ctrl.$validators.endpoint = (modelValue, viewValue) ->
if ctrl.$isEmpty(modelValue)
return true
if ENDPOINT_REGEXP.test(viewValue)
return true
# otherwise, this is invalid
return false
}
]