// EMAIL Validation, Also sets if mandatory to check or not
function validate(obj,mandatory)
{
if(mandatory == "True")
{
if(obj.value=="")
{
alert("Empty");
obj.focus();
return false;
}
var emailPat = /^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/;
// var emailPat = /^[\n <"']*([a-zA-Z0-9._-]@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
// var emailPat =/^[\n <"']*([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+)/;
var emailid=obj.value;
var matchArray = emailid.match(emailPat);
if (matchArray == null && obj.value!=="")
{
alert("Your email address seems incorrect. Please try again.");
obj.focus();
return false;
}
return true;
}
if(mandatory == "False")
{
var emailPat = /^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/;
// var emailPat = /^[\n <"']*([a-zA-Z0-9._-]@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
// var emailPat =/^[\n <"']*([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+)/;
var emailid=obj.value;
var matchArray = emailid.match(emailPat);
if (matchArray == null && obj.value!=="")
{
alert("Your email address seems incorrect. Please try again.");
obj.focus();
return false;
}
return true;
}
}
// Decimal Textbox control JavaScript with precision how many decimal places to be allowed
function extractNumber(obj, decimalPlaces, allowNegative)
{
var temp = obj.value;
// avoid changing things if already formatted correctly
var reg0Str = '[0-9]*';
if (decimalPlaces > 0) {
reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
} else if (decimalPlaces < 0) {
reg0Str += '\\.?[0-9]*';
}
reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
reg0Str = reg0Str + '$';
var reg0 = new RegExp(reg0Str);
if (reg0.test(temp)) return true;
// first replace all non numbers
var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
var reg1 = new RegExp(reg1Str, 'g');
temp = temp.replace(reg1, '');
if (allowNegative) {
// replace extra negative
var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
var reg2 = /-/g;
temp = temp.replace(reg2, '');
if (hasNegative) temp = '-' + temp;
}
if (decimalPlaces != 0) {
var reg3 = /\./g;
var reg3Array = reg3.exec(temp);
if (reg3Array != null) {
// keep only first occurrence of .
// and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
reg3Right = reg3Right.replace(reg3, '');
reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
}
}
obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
var key;
var isCtrl = false;
var keychar;
var reg;
if(window.event) {
key = e.keyCode;
isCtrl = window.event.ctrlKey
}
else if(e.which) {
key = e.which;
isCtrl = e.ctrlKey;
}
if (isNaN(key)) return true;
keychar = String.fromCharCode(key);
// check for backspace or delete, or if Ctrl was pressed
if (key == 8 || isCtrl)
{
return true;
}
reg = /\d/;
var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
return isFirstN || isFirstD || reg.test(keychar);
}
// Only Numeric Textbox COntrol
function EnsureNumeric()
{var k=window.event.keyCode;if(!((k>47&&k<58))){window.event.returnValue=false;}}
Subscribe to:
Post Comments (Atom)


0 comments:
Post a Comment