Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 18.191.192.113
/**************************************************************************************************
* FILE NAME��.......: Validate.js
* MODIFIED_DATE.....: 26/05/2009
* PROGRAMMER........: Beemaraj.V
* DESCRIPTION�......: This Script file is used for maintaining all Validating function.
*
* FUNCTION�.........: trim()
* PARAMETERS........: String as ARGUMENTS
* DESCRIPTION.......: The function is used to trim the given string.
*
* FUNCTION�.........: validateemail()
* PARAMETERS........: Email_id as ARGUMENTS
* DESCRIPTION.......: The function is used to Validate EmailId.
* FUNCTION�.........: acceptNumbersOnlyForModule()
* PARAMETERS........: Key Event as ARGUMENTS
* DESCRIPTION.......: The function is used to Accept Only Numbers in Textbox.
*
* FUNCTION�.........: validnumber()
* PARAMETERS........: no as ARGUMENTS
* DESCRIPTION.......: The function is used to validnumber for Textbox.
*
* FUNCTION�.........: isNumber()
* PARAMETERS........: no as ARGUMENTS
* DESCRIPTION.......: The function is used to check Enter charecter is Number.
*
* FUNCTION�.........: isLetter()
* PARAMETERS........: no as ARGUMENTS
* DESCRIPTION.......: The function is used to check Enter charecter is Letter.
*
* FUNCTION�.........: validDecimal()
* PARAMETERS........: no,dec as ARGUMENTS
* DESCRIPTION.......: The function is used to validDecimal.
*
***************************************************************************************************/
// Naveen
// position should be < 0
function tarkaRound(number, position) {
var zeors = 1;
for (var i = 1; i <= position; i++) {
zeors = zeors * 10;
}
return Math.round(number * zeors) / zeors;
}
// Trim the given String
function trim($str) {
return jQuery.trim($str);
}
function validateemail(emailid) {
var check =
/^([^0-9_@](\w+(?:\.\w+)*))@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if (emailid.match(check)) return true;
else return false;
}
function acceptNumbersOnlyForModule(evt) {
var charCode = evt.which ? evt.which : evt.keyCode;
console.log(charCode);
if (
charCode != 97 &&
charCode != 65 &&
charCode != 66 &&
charCode != 98 &&
((charCode > 41 &&
(charCode < 45 || charCode > 57) &&
charCode != 47 &&
charCode != 99 &&
charCode != 118 &&
charCode != 120) ||
charCode == 32 ||
charCode == 47)
)
return false;
return true;
}
function acceptNumbersOnlyForModuleABMP(evt) {
var charCode = evt.which ? evt.which : evt.keyCode;
if (
(charCode > 41 &&
(charCode < 46 || charCode > 57) &&
charCode != 97 &&
charCode != 78 &&
charCode != 110 &&
charCode != 112 &&
charCode != 109 &&
charCode != 98 &&
charCode != 47 &&
charCode != 80 &&
charCode != 77 &&
charCode != 66 &&
charCode != 69 &&
charCode != 101 &&
charCode != 65 &&
charCode != 99 &&
charCode != 118 &&
charCode != 120) ||
charCode == 32
)
return false;
return true;
}
function dotcount(s1, letter) {
return (s1.match(RegExp(letter, "g")) || []).length;
}
function AcceptDecNumbersOnly(evt, tnumb) {
var charCode = evt.which ? evt.which : evt.keyCode;
if (dotcount(tnumb, "\\.") > 0 && charCode == 46) return false;
if (
(charCode > 41 &&
(charCode < 45 || charCode > 57) &&
charCode != 46 &&
charCode != 47 &&
charCode != 99 &&
charCode != 118 &&
charCode != 120) ||
charCode == 32
)
return false;
return true;
}
function AcceptNumbersOnly(evt) {
var charCode = evt.which ? evt.which : evt.keyCode;
if (
charCode > 41 &&
(charCode < 45 || charCode > 57) &&
charCode != 47 &&
charCode != 99 &&
charCode != 118 &&
charCode != 120 &&
charCode != 78 &&
charCode != 65 &&
charCode != 97 &&
charCode != 110 &&
charCode != 77 &&
charCode != 80 &&
charCode != 109 &&
charCode != 112
)
return false;
return true;
}
function validateTime(time) {
var check = /^([0-9]{0,2})([\:]{1,1})([0-9]{0,2})$/;
if (time.match(check)) return true;
else return false;
}
function validnumberold(no) {
var dateRE = /^([0-9]{0,10})([\.]{0,1})([0-9]{0,9})$/;
if (no.match(dateRE)) return true;
else return false;
}
function validnumber(no) {
var dateRE = /^([0-9]{0,10})([\.]{0,1})([0-9]{0,9})$/;
if (no.match(dateRE)) return true;
else return false;
}
function isNumber(no) {
var dateRE = /^([0-9.])*$/;
return true;
if (no.match(dateRE)) return true;
else return false;
}
function isLetter(e, t) {
try {
if (window.event) {
var charCode = window.event.keyCode;
} else if (e) {
var charCode = e.which;
} else {
return true;
}
if (
(charCode > 64 && charCode < 91) ||
(charCode > 96 && charCode < 123) ||
charCode == 9 ||
charCode == 0 ||
charCode == 8
)
return true;
else return false;
} catch (err) {
alert(err.Description);
}
}
function charKeydown() {
var ch = String.fromCharCode(event.keyCode);
var filter = /[a-zA-Z ]/;
if (!filter.test(ch)) {
event.returnValue = false;
}
}
function dmydateformat(e, id) {
if (e.keyCode != 8) {
if ($("#" + id).val().length == 2) {
$("#" + id).val($("#" + id).val() + "/");
} else if ($("#" + id).val().length == 5) {
$("#" + id).val($("#" + id).val() + "/");
}
}
if (e.keyCode == 9) {
var value = document.getElementById(id).value;
if (value != "") {
var matchArray = value;
var day = matchArray.substring(0, 2);
var month = matchArray.substring(3, 5);
var year = matchArray.substring(6, 10);
if (month < 1 || month > 12) {
alert("Month must be between 1 and 12.");
document.getElementById(id).value = "";
setTimeout(function () {
document.getElementById(id).focus();
}, 0);
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
document.getElementById(id).value = "";
setTimeout(function () {
document.getElementById(id).focus();
}, 0);
return;
}
return;
}
}
}
function validDecimal(no, $dec) {
var dateRE = new RegExp(
"^([-]{0,1})([0-9]{0,10})([.]{0,1})([0-9]{0," + $dec + "})$"
);
if (no.match(dateRE)) return true;
else return false;
}
function roundNumber(number, decimal_points) {
if (!decimal_points) return Math.round(number);
if (number == 0) {
var decimals = "";
for (var i = 0; i < decimal_points; i++) decimals += "0";
return "0." + decimals;
}
var exponent = Math.pow(10, decimal_points);
var num = Math.round(number * exponent).toString();
return (
num.slice(0, -1 * decimal_points) + "." + num.slice(-1 * decimal_points)
);
}
function phpround(value, precision, mode) {
// Returns the number rounded to specified precision
//
// version: 1107.2516
// discuss at: http://phpjs.org/functions/round // + original by: Philip Peterson
// + revised by: Onno Marsman
// + input by: Greenseed
// + revised by: T.Wild
// + input by: meo // + input by: William
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// + input by: Josep Sanz (http://www.ws3.es/)
// + revised by: Rafal Kukawski (http://blog.kukawski.pl/)
// % note 1: Great work. Ideas for improvement: // % note 1: - code more compliant with developer guidelines
// % note 1: - for implementing PHP constant arguments look at
// % note 1: the pathinfo() function, it offers the greatest
// % note 1: flexibility & compatibility possible
// * example 1: round(1241757, -3); // * returns 1: 1242000
// * example 2: round(3.6);
// * returns 2: 4
// * example 3: round(2.835, 2);
// * returns 3: 2.84 // * example 4: round(1.1749999999999, 2);
// * returns 4: 1.17
// * example 5: round(58551.799999999996, 2);
// * returns 5: 58551.8
var m, f, isHalf, sgn; // helper variables precision |= 0; // making sure precision is integer
m = Math.pow(10, precision);
value *= m;
sgn = (value > 0) | -(value < 0); // sign of the number
isHalf = value % 1 === 0.5 * sgn;
f = Math.floor(value);
if (isHalf) {
switch (mode) {
case "PHP_ROUND_HALF_DOWN":
value = f + (sgn < 0); // rounds .5 toward zero
break;
case "PHP_ROUND_HALF_EVEN":
value = f + (f % 2) * sgn; // rouds .5 towards the next even integer
break;
case "PHP_ROUND_HALF_ODD":
value = f + !(f % 2); // rounds .5 towards the next odd integer
break;
default:
value = f + (sgn > 0); // rounds .5 away from zero }
}
return (isHalf ? value : Math.round(value)) / m;
}
}
function validateDate(ldate, id, evt) {
var pattern = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
var charCode = evt.which ? evt.which : evt.keyCode;
if (charCode == 9) {
if (ldate == null || ldate == "" || !pattern.test(ldate)) {
errMessage = "Invalid date\n";
alert(errMessage);
//$("#"+id).value('');
document.getElementById(id).value = "";
return;
} else {
var matchArray = ldate;
var day = matchArray.substring(0, 2);
var month = matchArray.substring(3, 5);
var year = matchArray.substring(6, 10);
if (month < 1 || month > 12) {
alert("Month must be between 1 and 12.");
$("#" + id).focus();
return;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
$("#" + id).focus();
return;
}
return;
}
}
}
Object.size = function (obj) {
var size = 0,
key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function to_upperx(id) {
var x = document.getElementById(id).value;
document.getElementById(id).value = x.toUpperCase();
}
|