1.Only Numeric value with one dot like 10.50:-
function isNumber(evt, element) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (
(charCode != 45 || $(element).val().indexOf('-') != -1) && // “-” CHECK MINUS, AND ONLY ONE.
(charCode != 46 || $(element).val().indexOf('.') != -1) && // “.” CHECK DOT, AND ONLY ONE.
(charCode < 48 || charCode > 57))
return false;
return true;
}
Call the above method onkeypress="return isNumber(event,this);"
2.Only Numeric value:-
<script type="text/javascript">
function numvalidate(text) {
// numeric with decimal
//var test_str = /(?!^0*$)(?!^0*\.0*$)^\d{1,9}(\.\d{1,2})?$/
// only numeric value
if (test_str.test(text.value))
{
if (text.value > 10000000)
{
alert("Please enter a valid Amount.");
text.focus();
return false;
}
return true;
}
else {
if (text.value == "")
return true;
alert("Please enter a valid Amount.");
text.focus();
return false;
}
}
</script>
Call below
<td>
<asp:TextBox ID="txtAmountLTC" runat="server" Text="" onblur="return numvalidate(this);" ToolTip="Only decimal value"></asp:TextBox>
</td>
3. "Only nemeric with two decimal values allowed for ex. 5.23"
<script type="text/javascript">
function QtyNPrice(me) {
var str = me.value;
var regexstr = /^[0-9]{1,12}(\.[0-9]{1,2})?$/;
if (!str.match(regexstr) && str.length > 0) {
alert("Only nemeric with two decimal values allowed for ex. 5.23");
me.focus();
}
}
</script>
<asp:TextBox ID="txtAmountLTC" runat="server" Text="" onblur="QtyNPrice(this);" ToolTip="Only decimal value"></asp:TextBox>
4. Confirmation message by client side code
<script type="text/javascript">
function ConfirmMsg(msg)
{
var r = confirm(msg);
if (r == true) {
return true;
}
else {
return false;
}
}
</script>
<asp:Button ID="btnResetAll" runat="server" Text="Reset All" onclick="btnResetAll_Click"
OnClientClick="return ConfirmMsg('Are you sure you want to reset this page?');" TabIndex="13" />
5. Valid PAN number
<script type="text/javascript">
function validatePANNo(idPAN) {
var obj = document.getElementById(idPAN);
//if (!validateTextBox(idPAN, 'Please enter PAN number')) { return false; }
var regexstr = /[A-Za-z]{5}\d{4}[A-Za-z]{1}/; var str = obj.value;
if (trim(str).length > 0 && trim(str).length < 11) {
if (!str.match(regexstr)) { alert("Please enter valid PAN."); obj.focus(); return false; }
else { return true; }
}
else {
alert("Please enter valid PAN."); obj.focus(); return false;
}
}
</script>
<td>
<span>PAN</span>
</td>
<td>
<asp:TextBox ID="txtPAN" runat="server" Text="" onblur="javascript:return validatePANNo('txtPAN'); "></asp:TextBox>
</td>
6. Only alphanumeric values are allowed.
<script type="text/javascript">
function isAlphanumeric(me) {
if (me.value.length > 0) {
var regexstr = /[^a-z 0-9.-\/\\ A-Z]/; regexstr.multiline = true; var str = me.value;
if (str.match(regexstr)) { alert("Only alphanumeric values are allowed."); me.focus(); me.select(); return false; }
} return true;
}
</script>
<td>
<span>Company Name</span>
</td>
<td>
<asp:TextBox ID="txtCompany" runat="server" Text="" onblur="javascript:return isAlphanumeric(this);" Width="98%" BorderWidth="0px" ReadOnly="true"></asp:TextBox>
</td>
7. Mobile number
<script type="text/javascript">
function isMobileNumber(me) {
if (me.value.length > 0) {
var regexstr = /[^0-9]/;
var str = me.value;
if (me.value.length > 10 || (str.match(regexstr))) {
alert("Only 10 digit mobile number is allowed");
}
}
}
</script>
<td>
<span>Mobile No.</span>
</td>
<td>
<asp:TextBox ID="txtMobile" runat="server" onblur="javascript:return isMobileNumber(this);"></asp:TextBox>
</td>
8.Count the Grid Row
<script type="text/javascript">
function grdRowCount(grdID,errMsg)
{
try{
var obj = document.getElementById(grdID);
if(obj.rows.length<1)
{
alert(errMsg);
return false;
}
else
{
return true;
}
}
catch(err){
alert(errMsg);
return false;
}
}
</script>
9.trim the String
function trim(str) {
str = str.replace(/^\s+/, '');
for (var i = str.length - 1; i >= 0; i--) {
if (/\S/.test(str.charAt(i))) { str = str.substring(0, i + 1); break; }
} return str;
}
10. Clear All controls of Div
function ClearAllControls(divName) {
var searchEles = document.getElementById(divName).children;
for (var i = 0; i < searchEles.length; i++) {
if (searchEles[i].tagName == 'INPUT') doc.value = "";
if (searchEles[i].tagName == 'SELECT') doc.selectedIndex = 0;
}
}
11. function isAlphabetBorrower(me) {
if (me.value.length > 0) {
var regexstr = /[^a-z ,. A-Z]/; var str = me.value;
if (str.match(regexstr)) { alert("Only alphabets and (,) are allowed."); me.focus(); me.select(); return false; }
} return true;
}
function isNumericBorrower(me) {
if (me.value.length > 0) {
var regexstr = /[^0-9,]/; var str = me.value;
if (str.match(regexstr)) { alert("Only Numeric and (,) are allowed without space."); me.focus(); me.select(); return false; }
} return true;
}
function isNumber(evt, element) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (
(charCode != 45 || $(element).val().indexOf('-') != -1) && // “-” CHECK MINUS, AND ONLY ONE.
(charCode != 46 || $(element).val().indexOf('.') != -1) && // “.” CHECK DOT, AND ONLY ONE.
(charCode < 48 || charCode > 57))
return false;
return true;
}
Call the above method onkeypress="return isNumber(event,this);"
2.Only Numeric value:-
<script type="text/javascript">
function numvalidate(text) {
// numeric with decimal
//var test_str = /(?!^0*$)(?!^0*\.0*$)^\d{1,9}(\.\d{1,2})?$/
// only numeric value
if (test_str.test(text.value))
{
if (text.value > 10000000)
{
alert("Please enter a valid Amount.");
text.focus();
return false;
}
return true;
}
else {
if (text.value == "")
return true;
alert("Please enter a valid Amount.");
text.focus();
return false;
}
}
</script>
Call below
<td>
<asp:TextBox ID="txtAmountLTC" runat="server" Text="" onblur="return numvalidate(this);" ToolTip="Only decimal value"></asp:TextBox>
</td>
3. "Only nemeric with two decimal values allowed for ex. 5.23"
<script type="text/javascript">
function QtyNPrice(me) {
var str = me.value;
var regexstr = /^[0-9]{1,12}(\.[0-9]{1,2})?$/;
if (!str.match(regexstr) && str.length > 0) {
alert("Only nemeric with two decimal values allowed for ex. 5.23");
me.focus();
}
}
</script>
<asp:TextBox ID="txtAmountLTC" runat="server" Text="" onblur="QtyNPrice(this);" ToolTip="Only decimal value"></asp:TextBox>
4. Confirmation message by client side code
<script type="text/javascript">
function ConfirmMsg(msg)
{
var r = confirm(msg);
if (r == true) {
return true;
}
else {
return false;
}
}
</script>
<asp:Button ID="btnResetAll" runat="server" Text="Reset All" onclick="btnResetAll_Click"
OnClientClick="return ConfirmMsg('Are you sure you want to reset this page?');" TabIndex="13" />
5. Valid PAN number
<script type="text/javascript">
function validatePANNo(idPAN) {
var obj = document.getElementById(idPAN);
//if (!validateTextBox(idPAN, 'Please enter PAN number')) { return false; }
var regexstr = /[A-Za-z]{5}\d{4}[A-Za-z]{1}/; var str = obj.value;
if (trim(str).length > 0 && trim(str).length < 11) {
if (!str.match(regexstr)) { alert("Please enter valid PAN."); obj.focus(); return false; }
else { return true; }
}
else {
alert("Please enter valid PAN."); obj.focus(); return false;
}
}
</script>
<td>
<span>PAN</span>
</td>
<td>
<asp:TextBox ID="txtPAN" runat="server" Text="" onblur="javascript:return validatePANNo('txtPAN'); "></asp:TextBox>
</td>
6. Only alphanumeric values are allowed.
<script type="text/javascript">
function isAlphanumeric(me) {
if (me.value.length > 0) {
var regexstr = /[^a-z 0-9.-\/\\ A-Z]/; regexstr.multiline = true; var str = me.value;
if (str.match(regexstr)) { alert("Only alphanumeric values are allowed."); me.focus(); me.select(); return false; }
} return true;
}
</script>
<td>
<span>Company Name</span>
</td>
<td>
<asp:TextBox ID="txtCompany" runat="server" Text="" onblur="javascript:return isAlphanumeric(this);" Width="98%" BorderWidth="0px" ReadOnly="true"></asp:TextBox>
</td>
7. Mobile number
<script type="text/javascript">
function isMobileNumber(me) {
if (me.value.length > 0) {
var regexstr = /[^0-9]/;
var str = me.value;
if (me.value.length > 10 || (str.match(regexstr))) {
alert("Only 10 digit mobile number is allowed");
}
}
}
</script>
<td>
<span>Mobile No.</span>
</td>
<td>
<asp:TextBox ID="txtMobile" runat="server" onblur="javascript:return isMobileNumber(this);"></asp:TextBox>
</td>
8.Count the Grid Row
<script type="text/javascript">
function grdRowCount(grdID,errMsg)
{
try{
var obj = document.getElementById(grdID);
if(obj.rows.length<1)
{
alert(errMsg);
return false;
}
else
{
return true;
}
}
catch(err){
alert(errMsg);
return false;
}
}
</script>
9.trim the String
function trim(str) {
str = str.replace(/^\s+/, '');
for (var i = str.length - 1; i >= 0; i--) {
if (/\S/.test(str.charAt(i))) { str = str.substring(0, i + 1); break; }
} return str;
}
10. Clear All controls of Div
function ClearAllControls(divName) {
var searchEles = document.getElementById(divName).children;
for (var i = 0; i < searchEles.length; i++) {
if (searchEles[i].tagName == 'INPUT') doc.value = "";
if (searchEles[i].tagName == 'SELECT') doc.selectedIndex = 0;
}
}
11. function isAlphabetBorrower(me) {
if (me.value.length > 0) {
var regexstr = /[^a-z ,. A-Z]/; var str = me.value;
if (str.match(regexstr)) { alert("Only alphabets and (,) are allowed."); me.focus(); me.select(); return false; }
} return true;
}
function isNumericBorrower(me) {
if (me.value.length > 0) {
var regexstr = /[^0-9,]/; var str = me.value;
if (str.match(regexstr)) { alert("Only Numeric and (,) are allowed without space."); me.focus(); me.select(); return false; }
} return true;
}
No comments:
Post a Comment