Sha256: 7f92c2e6ca3a494ec9df5619ccc824de33e5fdd715763045cf1b7681ba6d920b
Contents?: true
Size: 1.86 KB
Versions: 1
Compression:
Stored size: 1.86 KB
Contents
angular.module('EssayApp.directives').directive "checkFullPhone", ['countryCodeService', (countryCode) -> restrict: 'A' scope: true require: "ngModel" link: (scope, element, attrs, ngModel) -> PHONE_REGEXP = /^\s*\+?[\s\(]?(\d{1,10})[\s\(\)\._-]*(\d{0,6})[\s\(\)\._-]*((\d[\s-]?){6,12})\s*$/ validPhone = (value) -> return false if angular.isUndefined(value) return false if value.length is 0 value && PHONE_REGEXP.test(value) ngModel.$validators.full_phone = (value) -> validPhone(value) scope.$watch('country_coder.country_codes', (country_codes) -> if country_codes && country_codes.length > 0 && element.val() ngModel.$setValidity('country_code', ngModel.$validators.country_code(element.val()) ngModel.$setTouched() element.trigger 'focusout' ) ) ngModel.$validators.country_code = (value) -> if validPhone(value) && countryCode.country_codes && (countryCode.country_codes.length > 0) phone = countryCode.split_phone(value) if phone ngModel.$setValidity('phoneMaxSize', if attrs.phoneMaxSize phone[1].length <= attrs.phoneMaxSize else true ) ngModel.$setValidity('phoneMinSize', if attrs.phoneMinSize phone[1].length >= attrs.phoneMinSize else true ) scope.customer.customer_country_code = phone[0] scope.customer.customer_phone_number = phone[1] # console.log 'phone success:', phone return true else scope.customer.customer_country_code = null scope.customer.customer_phone_number = null # console.log 'phone fail:', value return false else # ngModel.$setValidity('full_phone', false) # true false ]
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
translation_cms-0.1.5 | app/assets/javascripts/app/directives/check_full_phone.js.coffee |