Click here to Skip to main content
15,887,812 members
Articles / Web Development / IIS
Article

A reusable form validator for ASP pages

Rate me:
Please Sign up or sign in to vote.
4.29/5 (7 votes)
27 Jun 2001CPOL3 min read 160.6K   1.2K   40   23
Some functions for client side HTML forms validation. Never write them again!

What it's all about

When writing a web application using ASP, you often have to create HTML based input forms for all sorts of data. E.g. user registration pages, questionnaires, data capture templates and so on. Most of the time this data is the further processed and stored somewhere, usually in a database.

To make sure that only valid data is entered, some checks should occur before it is stored somewhere. Valid means here reasonable in the current context (e.g. no birthdays in the future) as well as suitable for the data store, like limitations in length or data type.

This validation can take place on the client side via JavaScript or on the server within the receiving Active Server Page. Both have well known advantages and disadvantages. This article contains a method for the JavaScript variant.

Writing the same code again and again

As I wrote various web applications during the last years I had quite often the feeling that I'm doing the same stuff again and again, and actually it was more or less the same. After reusing my old stuff with cut-and-paste a couple of times I decided to build a more general solution, that can be used in all upcoming projects.

The mission objectives

  • Write once use everywhere
  • No dynamic code generation (ASP scripts that generate client side JavaScript.....)
  • Separate JavaScript code from HTML (move it into a separate file)
  • Browser independent

The solution

As I ruled out dynamic code generation, I had to come up with a trick to make the validation code independent of the names of the input fields and to provide the functionality to be able to check only some of the fields. This is the important point of the solution, as the input fields can be accessed from JavaScript via their names or their indices. Both may vary.
<script language="JavaScript" src="/formvalidator.js"></script>

<form name="RegisterUserForm" action="register.save.asp" method="post" 
      OnSubmit="return CheckForm(document.RegisterUserForm);">

Logon Name: <INPUT TYPE="TEXT" NAME="logon_name" VALUE="">

<INPUT TYPE="HIDDEN" NAME="CHK_logon_name" VALUE="STR|5|255|True|Logon name">

</form>

So what are we doing here? The first two lines are more or less stratight forward. Include the JavaScript file that contains the form checker code and include an OnSubmit event handler. The interesting part is the last hidden input field. It contains instructions for the form checker. In this case they are:

  • The field to be checked has the name logon_name
  • It's a string value
  • Minimum of 5 characters
  • Maximum of 255
  • It's a mandatory field
  • The friendly name (for the error message) is Logon name

For strings it's not too far beyond what HTML can do for you right out of the box. Basically only the enforcement of mandatory fields and the minimum string length are enhancements. It gets more interesting when it comes to numeric values and dates.

According to the features for strings the form checker checks these values for numeric values (integers and floats):

  • Minimum and maximum values (not character length)
  • Validity of the string. Only numeric characters are allowed.

And for dates:

  • Validity of the string. Format of the string
  • Minimum and maximum date
  • Validity of the date (e.g February 30th is not allowed)

So what the CheckForm function actually does, is to go through all form elements of the form passed as parameter. It the looks for the CHK_ prefix and interprets the values as instructions to check the content of the corresponding field.

Some further thoughts

The beauty of the solution lies in the fact, that you don't further mess up your ASP code with JavaScript stuff. But there is more. What if you would generate all the input fields automatically, let's say from some meta data that describes the design of your data store? So your ASP page would just create all the necessary input fields and - as it has the data type information right at hand - the hidden fields for the validation check. Then you get the proper checking routines for free.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Germany Germany
If you are not living on the edge you are wasting space Wink | ;)

Comments and Discussions

 
Questionhi!im new to java and need some help ere.. Pin
blackboxer25-Feb-07 23:19
blackboxer25-Feb-07 23:19 
AnswerRe: hi!im new to java and need some help ere.. Pin
Christian Graus25-Feb-07 23:27
protectorChristian Graus25-Feb-07 23:27 
QuestionWhy not use Validator control at server side? Pin
Jeason Zhao1-Sep-04 20:29
Jeason Zhao1-Sep-04 20:29 
GeneralDate Format again Pin
Member 119834324-Jun-04 13:19
Member 119834324-Jun-04 13:19 
GeneralNew code Pin
28-Jan-03 22:20
suss28-Jan-03 22:20 
Generalsome modifications Pin
DioX19-Oct-02 21:44
DioX19-Oct-02 21:44 
my new code:

- email validation.
- radiobutton validation.
- check validation.
- Realy int validation.
- strings validation with alphanumeric, alphabetical or all char allowed.
- select validation with not valid support.
- date with "/" or "-" separator.
and...

- background color in error.

Sorry but I´m spanish and the comments are in Spanish Smile | :)

/***********************************************************************************************************<br />
*                                                                                                          *<br />
*              Funcion realizada por Omar Sanchez, ENNEC soluciones (www.ennec.net)                        *  <br />
*               A raiz de un Javascript encontrado en el web, www.codeproject.com                         *<br />
*                                  Distribuida bajo licencia GPL                                           *<br />
*                                                                                                          *<br />
************************************************************************************************************<br />
*                                                                                                          *<br />
*                                                                                                          *<br />
* Esta funcion checkea los campos de un formulario segun una forma predefinida. Para que la funcion sepa   *<br />
* como ha de tratar cada campo, deberemos de poner un campo tipo hidden indicando su trato.                *<br />
*                                                                                                          *<br />
* Sintaxis:                                                                                                *<br />
* <input type="text" name="<nombre>">                                                                      *<br />
* <input type="hidden" name="CHK_<nombre>"                                                                 *<br />
* value="<tipo>[|<cod>][|<minimo>|<maximo>][|<no valido>]|<obligado>|<Nombre del campo>">                  *<br />
*                                                                                                          *<br />
*   NOTA: Los campos <tipo>,<min>,<max>,<obligado>,<Nombre del campo> son insensibles a MAYUSCULAS         *<br />
*                                                                                                          *<br />
* + tipo:                                                                                                  *<br />
*   · STR   : cadena, <cod> indica codificacio ALF->Alfabetica, ALN->Alfanumerica, ALL->Cualquiera         *<br />
* <input type="hidden" name="CHK_<nombre>" value="str|<cod>|<min>|<max>|<obligado>|<Nombre del campo>">    *<br />
*   · INT   : numero entero.                                                                               * <br />
* <input type="hidden" name="CHK_<nombre>" value="int|<min>|<max>|<obligado>|<Nombre del campo>">          *<br />
*   · FLOAT : numero decimal.                                                                              *<br />
* <input type="hidden" name="CHK_<nombre>" value="float|<min>|<max>|<obligado>|<Nombre del campo>">        *<br />
*   · DATE  : fecha (DD/MM/YYYY Ó DD-MM-YYYY).                                                             *<br />
* <input type="hidden" name="CHK_<nombre>" value="date|<min>|<max>|<obligado>|<Nombre del campo>">         *<br />
*   · MAIL : checkea que el campo tenga al menos una "@" y un ".", dos caracteres antes de la "@", entre   *<br />
*            la "@" y el "." al menos dos caracteres y al menos dos caracteres tras el punto y el final    *<br />
* <input type="hidden" name="CHK_<nombre>" value="mail|<obligado>|<Nombre del campo>">                     *<br />
*   · CHECK : Solo tiene un parametro que es TRUE o FALSE para caso como Acepto las condiciones.           *<br />
* <input type="hidden" name="CHK_<nombre>" value="check|<obligado>|<Nombre del campo>">                    *<br />
*   · RADIO : Solo tiene un parametro que es TRUE o FALSE para obligar a que selecciones uno o no          *<br />
* <input type="hidden" name="CHK_<nombre>" value="radio|<obligado>|<Nombre del campo>">                    *<br />
*   · SEL   : admite el parametro de obligacion asi como uno de campo no valido para la tipica division    *<br />
*               o para indicar que el primer campo no es valido si es un "Selecciona uno" indicar          *<br />
*               un valor para no valido identico a los value del option no valido.                         *<br />
* <input type="hidden" name="CHK_<nombre>" value="sel|<no valido>|<obligado>|<Nombre del campo>">          *<br />
*                                                                                                          *<br />
* + min/max:                                                                                               *<br />
*   · Valor minimo/maximo. En caso de ser una fecha, minima/maxima fecha admitidas.                        *<br />
*                                                                                                          *<br />
* + obligado:                                                                                              *<br />
*   · Admite true y false para indicar si el campo es obligatorio o no rellenarlo.                         *<br />
*                                                                                                          *<br />
* + Nombre del campo:                                                                                      *<br />
*   · Nombre para referirse al campo en los mensajes.                                                      *<br />
*                                                                                                          *  <br />
*                                                                                                          *<br />
* Para cargar las funciones de checkeo utilizar el siguiente codigo:                                       *<br />
*                                                                                                          *<br />
*    <script language="JavaScript" src="<ruta>formvalidator.js"></script>                                  *<br />
*                                                                                                          *<br />
*                                                                                                          *<br />
* A la hora de chekear el formulario antes de hacer el submit se ha de poner un boton en la forma:         *<br />
*                                                                                                          *<br />
*   <Input type="button" value="PULSAME" OnClick="CheckForm(this.form);>                                   *<br />
*                                                                                                          *<br />
***********************************************************************************************************/<br />
<br />
function CheckForm(form)<br />
{<br />
    var i;<br />
    var x;<br />
    var j;<br />
    var okis;<br />
    var arr; //para guardar el array de opciones.<br />
    var str; //variable con el valor del campo a checkear.<br />
    var campo_error = ""; //variable para el campo del error.<br />
    var error = ""; //variable para los errores.<br />
    var campo;  // variable del campo a checkear.<br />
    var bgcolor = "#FFFFFF"; // color normal de los diversos campos.<br />
    var bgerror = "#FFFF99"; // color para campos erroneos.<br />
    var salto = "\n"; //para modificar facilmente el salto de linea en cada error.<br />
    var previo = "- "; //un previo a cada linea de error.<br />
<br />
    for (i=0;i<form.elements.length;i++)<br />
    {<br />
        if(form.elements[i].name.substr(0,4) == "CHK_")<br />
        {           <br />
            <br />
            str = GetFieldValueByName(form,form.elements[i].name.substr(4));<br />
            <br />
            if(str != null)<br />
            {<br />
                campo=GetFieldByName(form,form.elements[i].name.substr(4));<br />
                for (x=0;x<form.elements.length;x++)  //volvemos a buscar por todos los campos<br />
                {<br />
                        if (form.elements[x].name == campo.name) //si se llaman igual<br />
                        { <br />
                            form.elements[x].style.background = bgcolor;<br />
                        }<br />
                }<br />
                str = Trim(str);<br />
                            <br />
                arr = form.elements[i].value.split("|");            <br />
<br />
                switch(arr[0].toUpperCase())<br />
                {<br />
                    case "STR":<br />
                        //check mandatory field                         <br />
                        if (str.length == 0){<br />
                            if  (arr[4].toUpperCase() == "TRUE")<br />
                            {<br />
                                error = error + previo + "El campo " + arr[5] + " es obligatorio" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        else{<br />
							switch (arr[1].toUpperCase())<br />
							{<br />
							case "ALF":<br />
								if (!IsAlpha(str))<br />
								{<br />
									error = error + previo + "El valor del campo " + arr[5] + " debe ser alfabetico" + salto ;<br />
                                    if (!campo_error){campo_error=campo};<br />
									campo.style.background = bgerror;<br />
								}<br />
							break;<br />
							case "ALN":<br />
								if (!IsAlphaNumeric(str))<br />
								{<br />
									error = error + previo + "El valor del campo " + arr[5] + " debe ser alfanumerico" + salto ;<br />
                                    if (!campo_error){campo_error=campo};<br />
									campo.style.background = bgerror;<br />
								}<br />
							break;<br />
							<br />
							}<br />
<br />
<br />
                            //check min length  <br />
                            if (str.length < parseInt(arr[2]))<br />
                            {<br />
                                error = error + previo + "El valor del campo " + arr[5] + " es demasiado corto" + salto ;<br />
                                <br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                            <br />
                            //check max length<br />
                            if (str.length > parseInt(arr[3]))<br />
                            {<br />
                                error = error + previo + "El valor del campo " + arr[5] + " es demasiado largo" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        break;<br />
                                            <br />
                    case "INT":<br />
                                                                <br />
                        //check mandatory field<br />
                        if (str.length == 0){<br />
                            if  (arr[3].toUpperCase() == "TRUE")<br />
                            {<br />
                                error = error + previo + "El campo " + arr[4] + " es obligatorio" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        else{                           <br />
                            //check sanity<br />
                            if(!(IsNumeric(str)))<br />
                            {<br />
                                error = error + previo + "El valor del campo " + arr[4] + " debe ser numerico" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
							else<br />
                            if(!(IsINT(str)))<br />
                            {<br />
                                error = error + previo + "El valor del campo " + arr[4] + " debe ser un entero" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                                               <br />
                            //check min value<br />
                            else<br />
							if (arr[1] != "x")<br />
                            {<br />
                                if (parseInt(str) < parseInt(arr[1]))<br />
                                {<br />
                                    error = error + previo + "El valor del campo " + arr[4] + " es demasiado bajo" + salto ;<br />
                                    if (!campo_error){campo_error=campo};<br />
                                    campo.style.background = bgerror;<br />
                                    <br />
                                }<br />
                            }<br />
                            <br />
                            //check max length<br />
                            else<br />
							if (arr[2] != "x")<br />
                            {<br />
                                if (parseInt(str) > parseInt(arr[2]))<br />
                                {<br />
                                    error = error + previo + "El valor del campo " + arr[4] + " es demasiado alto" + salto ;<br />
                                    if (!campo_error){campo_error=campo};<br />
                                    campo.style.background = bgerror;<br />
                                    <br />
                                }<br />
                            }<br />
                        }<br />
                        break;<br />
                    <br />
                    case "FLOAT":<br />
                        str= Replace(str,",",".");                                              <br />
                        //check mandatory field<br />
                        if (str.length == 0){<br />
                            if  (arr[3].toUpperCase() == "TRUE")<br />
                            {<br />
                                error = error + previo + "El campo " + arr[4] + " es obligatorio" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        else{                           <br />
                            //check sanity<br />
                            if(!(IsNumeric(str)))<br />
                            {<br />
                                error = error + previo + "El valor del campo " + arr[4] + " debe ser numerico" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                                                    <br />
                            //check min value<br />
                            else <br />
							if (arr[1] != "x")<br />
                            {<br />
                                if (parseFloat(str) < parseFloat(arr[1]))<br />
                                {<br />
                                    error = error + previo + "El valor del campo " + arr[4] + " es demasiado bajo" + salto ;<br />
                                    if (!campo_error){campo_error=campo};<br />
                                    campo.style.background = bgerror;<br />
                                    <br />
                                }<br />
                            }<br />
                            <br />
                            //check max length<br />
                            else<br />
							if (arr[2] != "x")<br />
                            {<br />
                                if (parseFloat(str) > parseFloat(arr[2]))<br />
                                {<br />
                                    error = error + previo + "El valor del campo " + arr[4] + " es demasiado alto" + salto ;<br />
                                    if (!campo_error){campo_error=campo};<br />
                                    campo.style.background = bgerror;<br />
                                    <br />
                                }<br />
                            }<br />
                        }                   <br />
                        break;<br />
                    case "RADIO":<br />
                        //check mandatory field<br />
                        if  (arr[1].toUpperCase() == "TRUE")<br />
                        {<br />
                            for (x=0;x<form.elements.length;x++)  //necesitamos buscar por todos los campos<br />
                            {<br />
                                if (form.elements[x].name == campo.name && form.elements[x].checked)<br />
                                { //si se llaman igual, miramos si estan checkeados o no<br />
                                    okis="TRUE"; //si lo estan,marcamos la salida como correcta<br />
                                }<br />
                            }<br />
                            if (!okis){ //ninguno estaba marcado :(<br />
                                error = error + previo + "Es obligatorio seleccionar una accion en el campo " + arr[2] + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                for (x=0;x<form.elements.length;x++)  //volvemos a buscar por todos los campos<br />
                                {<br />
                                    if (form.elements[x].name == campo.name) //si se llaman igual<br />
                                    { <br />
                                        form.elements[x].style.background = bgerror;<br />
                                    }<br />
                                }<br />
                            }<br />
                        }<br />
                        break;<br />
<br />
                    case "CHECK":<br />
                        //check mandatory field<br />
                        if  (arr[1].toUpperCase() == "TRUE" && !campo.checked)<br />
                        {<br />
                            error = error + previo + "Es obligatorio seleccionar el campo " + arr[2] + salto ;<br />
                            if (!campo_error){campo_error=campo};<br />
                            campo.style.background = bgerror;<br />
                        <br />
                        }<br />
                        break;<br />
<br />
                    case "SEL":<br />
                        //check mandatory field<br />
                        if (campo.selectedIndex <= 0){<br />
                            if  (arr[2].toUpperCase() == "TRUE")<br />
                            {<br />
                                error = error + previo + "Es obligatorio seleccionar el campo " + arr[3] + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        else {<br />
                            if (arr[1] == str)<br />
                            {<br />
                                error = error + previo + "La opcion seleccionada en el campo " + arr[3] + " no es valida" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        break;<br />
                    <br />
                    case "MAIL":<br />
                        //check mandatory field<br />
                        if (str.length == 0){<br />
                            if  (arr[1].toUpperCase() == "TRUE")<br />
                            {<br />
                                error = error + previo + "Es obligatorio introducir el campo " + arr[2] + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        else {<br />
                            if (!isEmail(str))<br />
                            {<br />
                                error = error + previo + "El E-mail introducido en el campo " + arr[2] + " no es valido" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        break;<br />
                                        <br />
                        <br />
                    case "DATE":<br />
                        <br />
                        //check mandatory field<br />
                        if (str.length == 0){<br />
                            if  (arr[3].toUpperCase() == "TRUE")<br />
                            {<br />
                                error = error + previo + "El campo " + arr[4] + " es obligatorio" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
                        }<br />
                        else{                           <br />
                            //check sanity<br />
                            if(!((IsDate(str,"/")) || (IsDate(str,"-"))))<br />
                            {<br />
                                error = error + previo + "El valor del campo " + arr[4] + " no es una fecha con formato (DD/MM/YYYY)" + salto ;<br />
                                if (!campo_error){campo_error=campo};<br />
                                campo.style.background = bgerror;<br />
                                <br />
                            }<br />
<br />
                            //check min value<br />
                            else<br />
							if (arr[1] != "x")<br />
                            {<br />
                                if (((GetDate(str,"/") < GetDate(arr[1],"/")) || (GetDate(str,"-") < GetDate(arr[1],"/"))) || ((GetDate(str,"/") < GetDate(arr[1],"-")) || (GetDate(str,"-") < GetDate(arr[1],"-"))))<br />
                                {<br />
                                    error = error + previo + "La fecha del campo " + arr[4] + " es anterior a la fecha minima admitida" + salto ;<br />
                                    if (!campo_error){campo_error=campo};<br />
                                    campo.style.background = bgerror;<br />
                                    <br />
                                }<br />
                            }<br />
                            <br />
                            //check max length<br />
                            else<br />
							if (arr[2] != "x")<br />
                            {<br />
                                if (((GetDate(str,"/") > GetDate(arr[2],"/")) || (GetDate(str,"-") > GetDate(arr[2],"/"))) || ((GetDate(str,"/") > GetDate(arr[2],"-")) || (GetDate(str,"-") > GetDate(arr[2],"-"))))<br />
                                {<br />
                                    error = error + previo + "La fecha del campo " + arr[4] + " es posterior a la fecha maxima admitida" + salto ;<br />
                                    if (!campo_error){campo_error=campo};<br />
                                    campo.style.background = bgerror;<br />
                                    <br />
                                }<br />
                            }<br />
                        }                   <br />
                        break;<br />
                }<br />
            }<br />
        }<br />
    }<br />
    if (error)<br />
    {<br />
        alert (error);<br />
        campo_error.focus();<br />
        return false;<br />
        <br />
    }<br />
    else {<br />
        //form.submit();<br />
        alert("TODO CORRECTO");<br />
		return true;<br />
    }<br />
}<br />
<br />
//============================================================================================<br />
<br />
function Replace(string,replacechar,replacewith) <br />
{<br />
    var temp = "";<br />
    var i;<br />
    <br />
    string = '' + string;<br />
    splitstring = string.split(replacechar);<br />
    for(i = 0; i < splitstring.length; i++)<br />
    {<br />
        if(i < (splitstring.length -1))<br />
            temp += splitstring[i] + replacewith;<br />
        else<br />
            temp += splitstring[i];<br />
    }<br />
    return temp;<br />
}<br />
<br />
//============================================================================================<br />
<br />
function GetFieldValueByName(form,name)<br />
{<br />
    var i;<br />
    <br />
    for (i=0;i<form.elements.length;i++)<br />
    {<br />
        if(form.elements[i].name == name)<br />
            return (form.elements[i].value);<br />
    }<br />
    return null;<br />
}<br />
<br />
function GetFieldByName(form,name)<br />
{<br />
    var i;<br />
    <br />
    for (i=0;i<form.elements.length;i++)<br />
    {<br />
        if(form.elements[i].name == name)<br />
            return (form.elements[i]);<br />
    }<br />
    return null;<br />
}<br />
<br />
/*<br />
<br />
======================= STANDARD HELPER FUNCTIONS BELOW =======================================<br />
<br />
*/<br />
function IsNumeric(str)<br />
{<br />
    var i;<br />
    for(i=0;i<str.length;i++)<br />
    {<br />
        if(!(   ((str.charAt(i) <= '9') && (str.charAt(i) >= '0')) ||<br />
                (str.charAt(i) == ' ') || (str.charAt(i) == '.') || (str.charAt(i) == ',') || (str.charAt(i) == '-')))<br />
            return(false);<br />
    }<br />
    return(true);<br />
}<br />
<br />
//============================================================================================<br />
<br />
function IsAlphaNumeric(str)<br />
{<br />
    var i;<br />
    for(i=0;i<str.length;i++)<br />
    {<br />
        if(!(   ((str.charAt(i) <= '9') && (str.charAt(i) >= '0')) ||<br />
                ((str.charAt(i) <= 'z') && (str.charAt(i) >= 'a')) ||<br />
                (str.charAt(i) == ' ') || (str.charAt(i) == '-') ||<br />
                (str.charAt(i) == 'ü') || (str.charAt(i) == 'ä') ||<br />
                (str.charAt(i) == 'ö') || (str.charAt(i) == 'Ü') ||<br />
                (str.charAt(i) == 'Ä') || (str.charAt(i) == 'Ö') ||<br />
                (str.charAt(i) == 'é') || (str.charAt(i) == 'ß') ||<br />
                ((str.charAt(i) <= 'Z') && (str.charAt(i) >= 'A')) ))<br />
            return(false);<br />
    }<br />
    return(true);<br />
}<br />
<br />
//============================================================================================<br />
<br />
function IsAlpha(str)<br />
{<br />
    var i;<br />
    <br />
    for(i=0;i<str.length;i++)<br />
    {<br />
        if(!(   ((str.charAt(i) <= 'z') && (str.charAt(i) >= 'a')) ||<br />
                (str.charAt(i) == ' ') || (str.charAt(i) == '-') ||<br />
                (str.charAt(i) == 'ü') || (str.charAt(i) == 'ä') ||<br />
                (str.charAt(i) == 'ö') || (str.charAt(i) == 'Ü') ||<br />
                (str.charAt(i) == 'Ä') || (str.charAt(i) == 'Ö') ||<br />
                (str.charAt(i) == 'é') || (str.charAt(i) == 'ß') ||<br />
                ((str.charAt(i) <= 'Z') && (str.charAt(i) >= 'A')) ))<br />
            return(false);<br />
    }<br />
    return(true);<br />
}<br />
<br />
//============================================================================================<br />
<br />
function Trim(str)<br />
{<br />
    //trim leding spaces<br />
    while(true)<br />
    {<br />
        if(str.charAt(0) == ' ')<br />
            str = str.substr(1);<br />
        else<br />
            break;<br />
    }<br />
    <br />
    //trim trailing spaces<br />
    while(true)<br />
    {<br />
        if(str.charAt(str.length-1) == ' ')<br />
            str = str.substr(0,str.length-1);<br />
        else<br />
            break;<br />
    }<br />
    return(str);    <br />
}<br />
<br />
//============================================================================================<br />
<br />
function IsDate(argDate,token)<br />
{<br />
    var date_split;<br />
    var i;<br />
    var tdate, tmonth, tyear;<br />
    <br />
    date_split = argDate.split(token);<br />
    <br />
    //check for date parts<br />
    if(date_split.length != 3)<br />
        return(false);<br />
        <br />
    //check for zero values<br />
    for(i=0;i<date_split.length;i++)<br />
    {<br />
        if(parseInt(date_split[i]) == 0)<br />
            return(false);<br />
    }<br />
    <br />
    //check for 4-digit year<br />
    if(date_split[2].length != 4)<br />
        return(false);<br />
        <br />
    //check for valid date, e.g. 29/02/1997<br />
    tdate = parseInt(date_split[0]);<br />
    tmonth = parseInt(date_split[1]);<br />
    tyear = parseInt(date_split[2]);<br />
    <br />
    var date = new Date(parseInt(date_split[2]),parseInt(date_split[1])-1,parseInt(date_split[0]));<br />
    <br />
    if(date.getDate() != tdate)<br />
        return(false);<br />
    <br />
    if(date.getMonth() != (tmonth-1))<br />
        return(false);<br />
    <br />
    if(date.getFullYear() != tyear)<br />
        return(false);<br />
        <br />
    return(true);<br />
}<br />
<br />
<br />
function GetDate(argDate,token)<br />
{<br />
    //use IsDate() first !!!!<br />
    <br />
    var date_split; <br />
    var tdate, tmonth, tyear;<br />
    <br />
    date_split = argDate.split(token);<br />
    <br />
        <br />
    <br />
    tdate = parseInt(date_split[0]);<br />
    tmonth = parseInt(date_split[1]);<br />
    tyear = parseInt(date_split[2]);<br />
    <br />
    return date = new Date(parseInt(date_split[2]),parseInt(date_split[1])-1,parseInt(date_split[0]));<br />
        <br />
}<br />
function isEmail(email)<br />
{<br />
  var theStr = new String(email)<br />
  var index = theStr.indexOf("@");<br />
  if (index > 1)<br />
  {<br />
    var pindex = theStr.indexOf(".",index);<br />
    if ((pindex > index+2) && (theStr.length > pindex+2))<br />
    return true;<br />
  }<br />
  return false;<br />
}<br />
<br />
function IsINT(entero)<br />
{<br />
for (var i = 0; i < entero.length; i++) {<br />
	if (entero.charAt(i) < "0" ||  entero.charAt(i) > "9") {<br />
		return false;<br />
    }<br />
}<br />
return true;<br />
<br />
}<br />
// ------------------------- end of code ------------------------------

GeneralRe: some modifications Pin
Horatiu CRISTEA3-Sep-03 4:13
Horatiu CRISTEA3-Sep-03 4:13 
GeneralDATE-format Pin
5-Jun-02 2:43
suss5-Jun-02 2:43 
GeneralRe: DATE-format Pin
Christian Tratz5-Jun-02 4:04
Christian Tratz5-Jun-02 4:04 
GeneralFocus on field with error Pin
5-Jun-02 1:54
suss5-Jun-02 1:54 
GeneralRe: Focus on field with error Pin
Anonymous18-Mar-03 18:49
Anonymous18-Mar-03 18:49 
GeneralRe: Focus on field with error Pin
PR-N-HOLE7-Oct-04 9:52
PR-N-HOLE7-Oct-04 9:52 
GeneralNew Feature added Pin
15-Apr-02 15:35
suss15-Apr-02 15:35 
Generaljust like that Pin
subas25-Feb-02 5:05
subas25-Feb-02 5:05 
GeneralDisabling of validation Pin
23-Jan-02 17:12
suss23-Jan-02 17:12 
GeneralRe: Disabling of validation Pin
Christian Tratz23-Jan-02 21:24
Christian Tratz23-Jan-02 21:24 
QuestionWhat about radio buttons Pin
14-Nov-01 11:58
suss14-Nov-01 11:58 
AnswerRe: What about radio buttons Pin
Mal Ross2-Apr-02 3:36
Mal Ross2-Apr-02 3:36 
GeneralToo Restricting!!! Pin
29-Jun-01 7:12
suss29-Jun-01 7:12 
GeneralRe: Too Restricting!!! Pin
2-Jul-01 23:38
suss2-Jul-01 23:38 
GeneralRe: Too Restricting!!! Pin
3-Jul-01 8:12
suss3-Jul-01 8:12 
GeneralRe: Too Restricting!!! Pin
Christian Tratz4-Jul-01 0:21
Christian Tratz4-Jul-01 0:21 
GeneralRe: Too Restricting!!! Pin
15-Feb-02 15:47
suss15-Feb-02 15:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.