Use Regular Expression by JavaScript
===============================
1 function validateEmail()
2 {
3 // Value to Validate. Ex. Your EMail Address TextBox
4 var EMailID = document.getElementById('txtEMail').value;
5
6 // Here, we set the Expression to Validate the Value for EMail Address.
7 var EMailValidate = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
8
9 // Test the Validator.
10 if( EMailValidate.test(EMailID))
11 {
12 alert('Right Email Address.');
13 }
14 else
15 {
16 alert('Wrong Email Address.');
17 }
18 }
Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts
Monday, August 10, 2009
Javascript to Allow only numbers in TextBox
Javascript to Allow only numbers in TextBox
======================================
function CheckKeyCode(e)
{
if (navigator.appName == "Microsoft Internet Explorer")
{
if((e.keyCode >= 48 && e.keyCode = 48 && e.charCode <= 57) || (e.charCode == 0))
{
return true;
}
else
{
return false;
}
}
}
// Add this code in your GridView control's RowDataBound Event.
((TextBox)e.Row.FindControl("txtDispOrder")).Attributes.Add("onkeypress", "javascript:return CheckKeyCode(event);");
======================================
function CheckKeyCode(e)
{
if (navigator.appName == "Microsoft Internet Explorer")
{
if((e.keyCode >= 48 && e.keyCode = 48 && e.charCode <= 57) || (e.charCode == 0))
{
return true;
}
else
{
return false;
}
}
}
// Add this code in your GridView control's RowDataBound Event.
((TextBox)e.Row.FindControl("txtDispOrder")).Attributes.Add("onkeypress", "javascript:return CheckKeyCode(event);");
Useful Javascript with Asp.Net
Open Popup Window in the Center of the screen.
=============================================
function OpenPop(ItemID)
{
var LeftPosition = (screen.width) ? (screen.width-505)/2 : 0;
var TopPosition = (screen.height) ? (screen.height-250)/2 : 0;
window.open('Pop_QuoteInfo.aspx?id='+ItemID,'MyTitle','height=250,width=505, top='+ TopPosition +', left='+LeftPosition+', scrollbars=yes, resizable=yes, status=no');
}
Javascript Trim() Function
=========================
function trim(inputString) {
// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
if (typeof inputString != "string") { return inputString; }
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") { // Check for spaces at the beginning of the string
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") { // Check for spaces at the end of the string
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings
}
return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
How to set Default Button in Asp.Net
===============================
Just, Simply add this code to your page_load() event in code file.
txtUserID.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnLogin.UniqueID + "').click();return false;}} else {return true}; ");
Enable / Disable Validator Control by Javascript
========================================
function EnableDisableControl()
{
var ctl1 = document.getElementById('RequiredValidator1');
// Disable
ValidatorEnable(ctl1, false);
// Enable
ValidatorEnable(ctl1, true);
}
Set/Get value from Popup page and Parent Page
========================================
Get Value in Popup page from Parent Page
---------------------------------------------------
// Write this Javascript in Popup Page
var ParentIDValue = window.opener.document.getElementById('').value;
alert(ParentIDValue);
Set Value in Parent Page from Popup Page
--------------------------------------------------
// Write this Javascript in Popup Page
window.opener.document.getElementById('').value = "Your Value From Popup Page..";
That's it !!
Hope you will like it.
=============================================
function OpenPop(ItemID)
{
var LeftPosition = (screen.width) ? (screen.width-505)/2 : 0;
var TopPosition = (screen.height) ? (screen.height-250)/2 : 0;
window.open('Pop_QuoteInfo.aspx?id='+ItemID,'MyTitle','height=250,width=505, top='+ TopPosition +', left='+LeftPosition+', scrollbars=yes, resizable=yes, status=no');
}
Javascript Trim() Function
=========================
function trim(inputString) {
// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
if (typeof inputString != "string") { return inputString; }
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") { // Check for spaces at the beginning of the string
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") { // Check for spaces at the end of the string
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings
}
return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
How to set Default Button in Asp.Net
===============================
Just, Simply add this code to your page_load() event in code file.
txtUserID.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnLogin.UniqueID + "').click();return false;}} else {return true}; ");
Enable / Disable Validator Control by Javascript
========================================
function EnableDisableControl()
{
var ctl1 = document.getElementById('RequiredValidator1');
// Disable
ValidatorEnable(ctl1, false);
// Enable
ValidatorEnable(ctl1, true);
}
Set/Get value from Popup page and Parent Page
========================================
Get Value in Popup page from Parent Page
---------------------------------------------------
// Write this Javascript in Popup Page
var ParentIDValue = window.opener.document.getElementById('').value;
alert(ParentIDValue);
Set Value in Parent Page from Popup Page
--------------------------------------------------
// Write this Javascript in Popup Page
window.opener.document.getElementById('').value = "Your Value From Popup Page..";
That's it !!
Hope you will like it.
Subscribe to:
Posts (Atom)