baas.io Javascript SDK v0.9.0 src/extensions/baas.io.validation.js

validation

property
Usergrid.validation
  • @class: Usergrid.validation
  • @author: Rod Simpson (rod@apigee.com)

Description

validation is a Singleton that provides methods for validating common field types

Source

Usergrid.validation = (function () {

  var usernameRegex = new RegExp("^([0-9a-zA-Z.-]){1,80}$");
  var nameRegex     = new RegExp("^[a-zA-Z0-9]+[a-zA-Z0-9_\.]{0,80}$");
  var emailRegex    = new RegExp("^(([0-9a-zA-Z]+[_\+.-]?)+@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$");
  var passwordRegex = new RegExp("^([0-9a-zA-Z`@#$%^&!?<>;:.,'\"~*-=+_\[\\](){}/\]{6,20}$)");
  var pathRegex     = new RegExp("^[a-zA-Z0-9\-\.\/]{2,80}$");
  var collectionNameRegex = new RegExp("^[0-9a-z\-]+[0-9a-z\-_]{3,80}$");

validateUsername

function
validateUsername()
  • @public:
  • @method: validateUsername
  • @param: {string}username- The string to test
  • @param: {function}failureCallback- (optional), the function to call on a failure
  • @return: {boolean}Returns true if string passes regex, false if not

Description

Tests the string against the allowed chars regex

Source

function validateUsername(username, failureCallback) {
    if (usernameRegex.test(username) && checkLength(username, 1, 80)) {
      return true;
    } else {
      if (failureCallback && typeof(failureCallback) === "function") {
        failureCallback(this.getUsernameAllowedChars());
      }
      return false;
    }
  }

getUsernameAllowedChars

function
getUsernameAllowedChars()
  • @public:
  • @method: getUsernameAllowedChars
  • @return: {string}Returns a string with the allowed chars

Description

Returns the regex of allowed chars

Source

function getUsernameAllowedChars(){
    return '1 ~ 80자까지 입력가능, 입력가능문자: "A-Z, a-z, 0-9, dot, and dash"';
  }

validateName

function
validateName()
  • @public:
  • @method: validateName
  • @param: {string}name- The string to test
  • @param: {function}failureCallback- (optional), the function to call on a failure
  • @return: {boolean}Returns true if string passes regex, false if not

Description

Tests the string against the allowed chars regex

Source

function validateName(name, failureCallback) {
    if (nameRegex.test(name) && checkLength(name, 0, 80)) {
      return true;
    } else {
      if (failureCallback && typeof(failureCallback) === "function") {
        failureCallback(this.getNameAllowedChars());
      }
      return false;
    }
  }

getNameAllowedChars

function
getNameAllowedChars()
  • @public:
  • @method: getNameAllowedChars
  • @return: {string}Returns a string with the allowed chars

Description

Returns the regex of allowed chars

Source

function getNameAllowedChars(){
    return '1 ~ 80자까지 입력가능, 입력가능문자: "A-Z, a-z, 0-9, dot, and dash"';
  }

validatePassword

function
validatePassword()
  • @public:
  • @method: validatePassword
  • @param: {string}password- The string to test
  • @param: {function}failureCallback- (optional), the function to call on a failure
  • @return: {boolean}Returns true if string passes regex, false if not

Description

Tests the string against the allowed chars regex

Source

function validatePassword(password, failureCallback) {
    if (passwordRegex.test(password) && checkLength(password, 5, 16)) {
      return true;
    } else {
      if (failureCallback && typeof(failureCallback) === "function") {
        failureCallback(this.getPasswordAllowedChars());
      }
      return false;
    }
  }

getPasswordAllowedChars

function
getPasswordAllowedChars()
  • @public:
  • @method: getPasswordAllowedChars
  • @return: {string}Returns a string with the allowed chars

Description

Returns the regex of allowed chars

Source

function getPasswordAllowedChars(){
    return '6 ~ 20자까지 입력가능, 입력가능문자: "A-Z, a-z, 0-9", 입력가능특수문자 : "`@#$%^&!?<>;:.,\'"~*-=+_[](){}/"';
  }

validateEmail

function
validateEmail()
  • @public:
  • @method: validateEmail
  • @param: {string}email- The string to test
  • @param: {function}failureCallback- (optional), the function to call on a failure
  • @return: {boolean}Returns true if string passes regex, false if not

Description

Tests the string against the allowed chars regex

Source

function validateEmail(email, failureCallback) {
    if (emailRegex.test(email)) {
      return true;
    } else {
      if (failureCallback && typeof(failureCallback) === "function") {
        failureCallback(this.getEmailAllowedChars());
      }
      return false;
    }
  }

getEmailAllowedChars

function
getEmailAllowedChars()
  • @public:
  • @method: getEmailAllowedChars
  • @return: {string}Returns a string with the allowed chars

Description

Returns the regex of allowed chars

Source

function getEmailAllowedChars(){
    return 'Email 기본 형태: e.g. baas@Baas.io';
  }

validatePath

function
validatePath()
  • @public:
  • @method: validatePath
  • @param: {string}path- The string to test
  • @param: {function}failureCallback- (optional), the function to call on a failure
  • @return: {boolean}Returns true if string passes regex, false if not

Description

Tests the string against the allowed chars regex

Source

function validatePath(path, failureCallback) {
    if (pathRegex.test(path) && checkLength(path, 2, 80)) {
      return true;
    } else {
      if (failureCallback && typeof(failureCallback) === "function") {
        failureCallback(this.getPathAllowedChars());
      }
      return false;
    }
  }

getPathAllowedChars

function
getPathAllowedChars()
  • @public:
  • @method: getPathAllowedChars
  • @return: {string}Returns a string with the allowed chars

Description

Returns the regex of allowed chars

Source

function getPathAllowedChars(){
    return '2 ~ 80자까지 입력가능, 입력가능문자: "/, a-z, 0-9, dot, and dash"';
  }

validateCollectionName

function
validateCollectionName()
  • @public:
  • @method: validateTitle
  • @param: {string}title- The string to test
  • @param: {function}failureCallback- (optional), the function to call on a failure
  • @return: {boolean}Returns true if string passes regex, false if not

Description

Tests the string against the allowed chars regex

Source

function validateCollectionName(name, failureCallback) {
    if (collectionNameRegex.test(name) && checkLength(name, 4, 80)) {
      return true;
    } else {
      if (failureCallback && typeof(failureCallback) === "function") {
        failureCallback(this.getCollectionNameAllowedChars());
      }
      return false;
    }
  }

getCollectionNameAllowedChars

function
getCollectionNameAllowedChars()
  • @public:
  • @method: getTitleAllowedChars
  • @return: {string}Returns a string with the allowed chars

Description

Returns the regex of allowed chars

Source

function getCollectionNameAllowedChars(){
    return '"a-z,0-9,dash" 로 시작하고 "_,dash,0-9,a-z" 로 구성된 4~80의 문자열';
  }

checkLength

function
checkLength()
  • @public:
  • @method: checkLength
  • @param: {string}string- The string to test
  • @param: {integer}min- the lower bound
  • @param: {integer}max- the upper bound
  • @return: {boolean}Returns true if string is correct length, false if not

Description

Tests if the string is the correct length

Source

function checkLength(string, min, max) {
    if (string.length > max || string.length < min) {
      return false;
    }
    return true;
  }

isUUID

function
isUUID()
  • @public:
  • @method: isUUID
  • @param: {string}uuidThe string to test
  • @returns: {Boolean} true if string is uuid

Description

Tests if the string is a uuid

Source

function isUUID (uuid) {
    var uuidValueRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
    if (!uuid) return false;
    return uuidValueRegex.test(uuid);
  }

  return {
    validateUsername:validateUsername,
    getUsernameAllowedChars:getUsernameAllowedChars,
    validateName:validateName,
    getNameAllowedChars:getNameAllowedChars,
    validatePassword:validatePassword,
    getPasswordAllowedChars:getPasswordAllowedChars,
    validateEmail:validateEmail,
    getEmailAllowedChars:getEmailAllowedChars,
    validatePath:validatePath,
    getPathAllowedChars:getPathAllowedChars,
    validateCollectionName:validateCollectionName,
    getCollectionNameAllowedChars:getCollectionNameAllowedChars,
    isUUID:isUUID
  }
})();