dojox/validate/br (version 1.10)

See the dojox/validate/br reference documentation for more information.

Property Summary

Method Summary

  • check(form,profile) validates user input of an HTML form based on input profile
  • computeCnpjDv(value) Generate the DV code (checksum part) for a Cnpj number
  • computeCpfDv(value) Generate the DV code (checksum part) for a CPF number
  • evaluateConstraint(profile,constraint,fieldName,elem) Evaluates dojo.validate.check() constraints that are specified as array arguments
  • getEmailAddressList(value,flags) Check if value is an email address list.
  • isEmailAddress(value,flags) Checks if a string could be a valid email address
  • isEmailAddressList(value,flags) Checks if a string could be a valid email address list.
  • isInRange(value,flags) Validates whether a string denoting a number is between a max and min.
  • isIpAddress(value,flags) Validates an IP address
  • isNumberFormat(value,flags) Validates any sort of number based format
  • isPhoneNumber(value) Validates 10 US digit phone number for several common formats
  • isSocialSecurityNumber(value) Validates social security number
  • isState(value,flags) Validates US state and territory abbreviations.
  • isText(value,flags) Checks if a string has non whitespace characters.
  • isUrl(value,flags) Checks if a string could be a valid URL
  • isValidCnpj(value) Validates a CNPJ/CGC number
  • isValidCpf(value) Validates a CPF number
  • isValidCreditCard(value,ccType) Validate a credit card number by type with Luhn checking.
  • isValidCreditCardNumber(value,ccType) Checks if value matches the pattern for that card or any card types if none is specified
  • isValidCvv(value,ccType) Validate the security code (CCV) for a passed credit-card type.
  • isValidIsbn(value) Validate ISBN-10 or ISBN-13 based on the length of value
  • isValidLuhn(value) Validate a String value against the Luhn algorithm.
  • isZipCode(value) Validates U.S. zip-code

Properties

_cardInfo

A dictionary list of credit card abbreviations

_isInRangeCache
Defined by: dojox/validate/_base

Methods

check(form,profile)

validates user input of an HTML form based on input profile

returns an object that contains several methods summarizing the results of the validation

Parameter Type Description
form HTMLFormElement

form to be validated

profile Object

specifies how the form fields are to be validated {trim:Array, uppercase:Array, lowercase:Array, ucfirst:Array, digit:Array, required:Array, dependencies:Object, constraints:Object, confirm:Object}

computeCnpjDv(value)
Defined by dojox/validate/br

Generate the DV code (checksum part) for a Cnpj number

Parameter Type Description
value String

The CGC number in ##.###.###/#### or ############ format

computeCpfDv(value)
Defined by dojox/validate/br

Generate the DV code (checksum part) for a CPF number

Parameter Type Description
value String

The CPF number in ######### format

evaluateConstraint(profile,constraint,fieldName,elem)

Evaluates dojo.validate.check() constraints that are specified as array arguments

The arrays are expected to be in the format of:

constraints:{
        fieldName: [functionToCall, param1, param2, etc.],
        fieldName: [[functionToCallFirst, param1],[functionToCallSecond,param2]]
}

This function evaluates a single array function in the format of: [functionName, argument1, argument2, etc]

The function will be parsed out and evaluated against the incoming parameters.

Parameter Type Description
profile undefined

The dojo.validate.check() profile that this evaluation is against.

constraint Array

The single [] array of function and arguments for the function.

fieldName undefined

The form dom name of the field being validated.

elem undefined

The form element field.

getEmailAddressList(value,flags)
Defined by dojox/validate/web

Check if value is an email address list. If an empty list is returned, the value didn't pass the test or it was empty.

Parameter Type Description
value String
flags Object
Optional

An object (same as dojo.validate.isEmailAddressList)

isEmailAddress(value,flags)
Defined by dojox/validate/web

Checks if a string could be a valid email address

Parameter Type Description
value String
flags Object
Optional
  • flags.allowCruft Allow address like <mailto:foo@yahoo.com>. Default is false.
  • flags in regexp.host can be applied.
  • flags in regexp.ipAddress can be applied.
  • flags in regexp.tld can be applied.
isEmailAddressList(value,flags)
Defined by dojox/validate/web

Checks if a string could be a valid email address list.

Parameter Type Description
value String
flags Object
Optional
  • flags.listSeparator The character used to separate email addresses. Default is ";", ",", "\n" or " ".
  • flags in regexp.emailAddress can be applied.
  • flags in regexp.host can be applied.
  • flags in regexp.ipAddress can be applied.
  • flags in regexp.tld can be applied.
isInRange(value,flags)

Validates whether a string denoting a number is between a max and min.

Parameter Type Description
value String
flags Object
Optional

{max:Number, min:Number, decimal:String}

  • flags.max A number, which the value must be less than or equal to for the validation to be true.
  • flags.min A number, which the value must be greater than or equal to for the validation to be true.
  • flags.decimal The character used for the decimal point. Default is ".".
isIpAddress(value,flags)
Defined by dojox/validate/web

Validates an IP address

Supports 5 formats for IPv4: dotted decimal, dotted hex, dotted octal, decimal and hexadecimal. Supports 2 formats for Ipv6.

Parameter Type Description
value String
flags Object
Optional

All flags are boolean with default = true.

  • flags.allowDottedDecimal Example, 207.142.131.235. No zero padding.
  • flags.allowDottedHex Example, 0x18.0x11.0x9b.0x28. Case insensitive. Zero padding allowed.
  • flags.allowDottedOctal Example, 0030.0021.0233.0050. Zero padding allowed.
  • flags.allowDecimal Example, 3482223595. A decimal number between 0-4294967295.
  • flags.allowHex Example, 0xCF8E83EB. Hexadecimal number between 0x0-0xFFFFFFFF. Case insensitive. Zero padding allowed.
  • flags.allowIPv6 IPv6 address written as eight groups of four hexadecimal digits.
  • flags.allowHybrid IPv6 address written as six groups of four hexadecimal digits followed by the usual 4 dotted decimal digit notation of IPv4. x:x:x:x:x:x:d.d.d.d
isNumberFormat(value,flags)

Validates any sort of number based format

Validates any sort of number based format. Use it for phone numbers, social security numbers, zip-codes, etc. The value can be validated against one format or one of multiple formats.

Format Definition

#        Stands for a digit, 0-9.
?        Stands for an optional digit, 0-9 or nothing.

All other characters must appear literally in the expression.

Parameter Type Description
value String
flags Object
Optional
  • flags.format A string or an Array of strings for multiple formats.
Returns:undefined

Examples

Example 1

"(###) ###-####"       ->   (510) 542-9742
"(###) ###-#### x#???" ->   (510) 542-9742 x153
"###-##-####"          ->   506-82-1089       i.e. social security number
"#####-####"           ->   98225-1649        i.e. zip code

Example 2

require(["dojox/validate/_base"], function(validate){
    // returns true:
    validate.isNumberFormat("123-45", { format:"###-##" });
});     

Example 3

Check Multiple formats:

require(["dojox/validate/_base"], function(validate){
    validate.isNumberFormat("123-45", {
        format:["### ##","###-##","## ###"]
});
isPhoneNumber(value)
Defined by dojox/validate/us

Validates 10 US digit phone number for several common formats

Parameter Type Description
value String

The telephone number string

Returns:Boolean
isSocialSecurityNumber(value)
Defined by dojox/validate/us

Validates social security number

Parameter Type Description
value String
isState(value,flags)
Defined by dojox/validate/us

Validates US state and territory abbreviations.

Parameter Type Description
value String

A two character string

flags Object
Optional
  • flags.allowTerritories Allow Guam, Puerto Rico, etc. Default is true.
  • flags.allowMilitary Allow military 'states', e.g. Armed Forces Europe (AE). Default is true.
isText(value,flags)

Checks if a string has non whitespace characters. Parameters allow you to constrain the length.

Parameter Type Description
value String
flags Object
Optional

{length: Number, minlength: Number, maxlength: Number}

  • flags.length If set, checks if there are exactly flags.length number of characters.
  • flags.minlength If set, checks if there are at least flags.minlength number of characters.
  • flags.maxlength If set, checks if there are at most flags.maxlength number of characters.
isUrl(value,flags)
Defined by dojox/validate/web

Checks if a string could be a valid URL

Parameter Type Description
value String
flags Object
Optional
  • flags.scheme Can be true, false, or [true, false]. This means: required, not allowed, or either.
  • flags in regexp.host can be applied.
  • flags in regexp.ipAddress can be applied.
  • flags in regexp.tld can be applied.
isValidCnpj(value)
Defined by dojox/validate/br

Validates a CNPJ/CGC number

Parameter Type Description
value String

The CNPJ/CGC number in ##.###.###/####-##, ########/####-##,

######-## or ############## format
isValidCpf(value)
Defined by dojox/validate/br

Validates a CPF number

Parameter Type Description
value String

The CPF number in #########-## or ###########, format

isValidCreditCard(value,ccType)

Validate a credit card number by type with Luhn checking.

Checks if a credit card type matches the # scheme in a passed value, and if the Luhn checksum is accurate (unless its an Enroute card, in which case the checkSum is skipped), returning a Boolean to check against.

Parameter Type Description
value String | Int

A Value (credit card number) to validate

ccType String

A credit-card abbreviation.

Examples

Example 1

if(dojox.validate.isValidCreditCard("12345", "mc")){
    console.log('inconceivable');
}
isValidCreditCardNumber(value,ccType)

Checks if value matches the pattern for that card or any card types if none is specified

Parameter Type Description
value String | Int

CC #, white spaces and dashes are ignored

ccType String
Optional

One of the abbreviation values in dojox.validate._cardInfo -- if Omitted, function returns a | delimited string of matching card types, or false if no matches found.

isValidCvv(value,ccType)

Validate the security code (CCV) for a passed credit-card type.

Parameter Type Description
value String | Int
ccType String
isValidIsbn(value)
Defined by dojox/validate/isbn

Validate ISBN-10 or ISBN-13 based on the length of value

Parameter Type Description
value String

An ISBN to validate

Returns:Boolean
isValidLuhn(value)

Validate a String value against the Luhn algorithm.

Validate a String value against the Luhn algorithm to verify its integrity.

Parameter Type Description
value String
isZipCode(value)
Defined by dojox/validate/us

Validates U.S. zip-code

Parameter Type Description
value String
Error in the documentation? Can’t find what you are looking for? Let us know!