UNPKG

ldx-widgets

Version:

widgets

41 lines (31 loc) 1.29 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