6 * Various form validation methods.
9 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
12 function testRegExp(form_name, element_name, re) {
13 return new RegExp(re).test(document.forms[form_name].elements[element_name].value);
16 function validateString(form_name, element_name) {
17 return (document.forms[form_name].elements[element_name].value.length > 0);
20 function validateSelection(form_name, element_name) {
21 return (document.forms[form_name].elements[element_name].selectedIndex > 0);
24 function validateCheckBox(form_name, element_name) {
25 return document.forms[form_name].elements[element_name].checked;
28 function validateCleanString(form_name, element_name) {
29 return testRegExp(form_name, element_name, '^[A-Za-z0-9_]+$');
32 function validateEmail(form_name, element_name) {
33 return testRegExp(form_name, element_name, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$');
36 function validateAbsUrl(form_name, element_name) {
37 return testRegExp(form_name, element_name, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+$');
40 function validateNumber(form_name, element_name, allow_blank) {
41 return (!allow_blank && value == '') ? false : testRegExp(form_name, element_name, '^-?[0-9]*\\.?[0-9]*$');
44 function validateSize(form_name, element_name,) {
45 return testRegExp(form_name, element_name, '^[0-9]+(px|%)?$');
48 function validateID(form_name, element_name,) {
49 return testRegExp(form_name, element_name, '^[A-Za-z_]([A-Za-z0-9_])*$');