NativeSoft Validators library

The script offers several functions that usually are needed during a web development process.

The main scope of this library is to eliminate the need of custom javascripts for control validation. Using the library you can use control custom attributes instead of javascripts for doing basic and complex validations like “isnumeric”, min/max values, value in control x bigger/smaller than value in control y and even more complicated checks like value from control x checks complex math functions (ex: (a+b)/c -1/d) etc).
More, we added even FORMULA functionality, meaning it is possibile to set a control value based on a custom formula, similar to Excel functions.

The custom control attributes we created are:

  • valmin : minimum value
  • validatefunction: a custom validation js function for special cases. the function must start with ‘validate’ word.
  • formula: the forumla used for the control value
  • isnumber: selfexplanatory.
  • isrequired: selfexplanatory. 1, yes, true as true and  false, no, 0 as false. however, if used toghether with min value it has priority. if isrequired=false and value is blank the min/max or anyother validation will not be fired,allowing complex validation, allowing null values too.
  • decimals: number of decimals to be displayed. If given, the numbers will be formated also.
  • digitsep: the separator to be used for decimals, if is not standard
  • regexpattern: the regexpattern that control must fit
  • checkexpression: a javascript expression that will be checked. To give control values inside you must use $ special character. if you control name is ‘BALANCE’ then use $BALANCE$ inside checkexpression or Formula attribute. Also $this$ can be used for self value.
  • checkexpressionfailure: the custom message that will be displayed when validation failed
  • requiredText: checks if control contains the specified text (ex: useful for number prefixes or other similar cases)
  • lenmax/lenmin : max/min length of a string. Usefull especially with textarea controls, they dont have a HTML standard max function


First we added a few functions to the String prototype :


formatNumber(decimals, digitSep, decimalSep)

“1234567.245”.formatNumber(1,”,”,”.”) returns 1,234,567.2

“1234567.248”.formatNumber(2,”#”,”@”) returns 1#234#567.24 (caution: does not do math rounding )



removes the digit separator from the String data and returns a clean number



“hello”.isNumeric() returns false while “12,444,234.302”.isNumeric() returns true


* example: “this is {0} and {1}”.format(‘a’,’b’) returns “this is a and b”
* @returns {String}

String.prototype.format = function()

formats a string with values like in sql statement: ex: “ {0} + {1} “.format(“a”,”b”) becomes “a+b”


replaceAll ()


* replaces ALL. the ignore param reffers to ignore case
* @param str1
* @param str2
* @param ignore
* @returns

String.prototype.replaceAll = function(str1, str2, ignore)

a function that replaces ALL appeareances of a string. Why this function? Because JavaScript does not have it! The included replace function does not replace ALL.



returns a “interpreted” in html text (ex:  gigi&quote becomes ‘ gigi”’

compareValues(a, b)

returns -1 (a<b),0(a==b), 1(a>b). is working correctly with both text and numbers. The standard a>b will return false for “111”>”99”

validateEmail (email) 

validates a string as email




Declare the form:

<form action=“userdetails” method=“post” id=“userdetails” name=“userdetails” onsubmit=”return verifysubmit(‘userdetails’,’submit_errors’)”>

verifysubmit is a function included in the script library.

userdetails=the form id

submit_errors=The  “submit_errors” value is the div id where the errors will be displayed. If null or doesn’t exists the errors will be shown in alert


<div align=“center”

id=“submit_errors” style=”display: block; margin:0px; border-color:blue;  color:red;background-color:yellow“></div>




<input  id=“email” name=“email” validatefunction=“Email” class=“ctrl” value =<%=user.getEmail()%> />


Above the validatefunction attribute will tell the validator to call the function validateEmail (validatexxxxx, where xxxxx is the attribute value) and pass the control value as parameter. So if you have custom validation function you can use validatefunction attribute



<td align=left  colspan=“2” id=“t_phone”>Phone:</td>

<td bgcolor=“#ffffff” colspan=“5”><input id=“phone” isrequired=“false” regexpattern=“^[\d\.\-]+$” regexpatternfailure=“phone number invalid” checkexpression=“$phone>10”   lenmin=“10” valmin=“999”   name=“phone” class=“ctrl” value =“” /></td>



Above you can see several attributes:


<input type=“password”  id=“pass” checkexpression=“‘$pass’==’$pass2′”  isrequired=“false” lenmin=“4” lenmax=“10” lenmin=“4”  name=“pass” class=“ctrl” value =“” />


<input isrequired=“false” lenmin=“4” checkexpression=“‘$pass’==’$pass2′” checkexpressionfailure=“Password and Password Verify  doesnt match!” type=“password”  id=“pass2” name=“pass2” class=“ctrl” value =“” />


Note: before calling the verifysubmit function you may set the variable debuginfo=true in order to see debug information.



Download link: nativesoftvalidator

Responses are currently closed, but you can trackback from your own site.

Comments are closed.