UNPKG

ldx-widgets

Version:

widgets

71 lines (55 loc) 2.14 kB
module.exports = isAlphabetsOnly: (string) -> return /^[a-zA-Z]+$/.test string isAlphaNumericOnly: (string) -> return /^[a-zA-Z\d]*$/.test string isAlphaNumericWithSpaces: (string) -> return /^[A-Za-z\d\s]*$/.test string isValidTitle: (string) -> return /^[a-zA-Z'"!@#$%&*()-_+:;.,?\/0-9\s]+$/.test string # Must be positive, no decimals isPositiveWholeNumber: (num) -> return /^\d+$/.test num # Allows decimals and negatives isNumeric: (num) -> return /^-?[0-9]\d*(\.\d+)?$/.test num isValidEmail : (addr) -> # modified RFC 2822 - http://www.regular-expressions.info/email.html return /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i.test addr isValidName: (name) -> # must be for aplhabets, apostrophe, white space or hyphen only return /^[a-zA-Z' \-]+$/.test name isValidPhone: (num) -> num = String(num) # Allow an empty phone numnber field if num.length is 0 then return true # Strip out parentheses and hyphens and spaces num = num.replace(/[\-\(\)\s]/g, "") # Require a ten digit number if num.length isnt 10 then return false # Check for only numbers return @isNumericOnly num isValidNhs: (nhs) -> nhsNumber = nhs.replace /\s/g, '' # if there are not 10 digits then not valid return no if nhsNumber.length < 10 mod11 = 0 factor = 10 # for the first 9 digits starting from the left for digit in nhsNumber when factor > 1 # multi the digit by the factor then add to mod 11 mod11 += digit*factor # descrease factor by 1 factor -= 1 # get the modulus and the check digit (right most digit) modulus = 11 - (mod11 % 11) checkDigit = parseInt(nhsNumber[9]) # rules: # modulus and check digit are equal then valid # modulus is 11 and and check digit is 0 then valid # modulus is 10 then not valid # everything else not valid if modulus is checkDigit or (modulus is 11 and checkDigit is 0) return yes else return no