JavaScript - javascript fn

Asked By chitra ganapathy
11-Feb-12 06:22 AM
hi, i need to enter address in textbox, so it should accepts only character, numbers,/ and comma and dot...
have any idea
  Sandeep Mittal replied to chitra ganapathy
11-Feb-12 06:52 AM
<script type="text/javascript">
function validate(key) {
  //getting key code of pressed key
  var keycode = (key.which) ? key.which : key.keyCode;
  var phn = document.getElementById('txtPhn');
  //comparing pressed keycodes
  if ((keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122) || (keycode >= 48 && keycode <= 57) || keycode == 44 || keycode == 46 || keycode == 47)
    return true;
  else
    return false;
}
</script>

<asp:TextBox ID="Textbox1" onkeypress="return validate(event)" runat="server"></asp:TextBox>
  Suchit shah replied to chitra ganapathy
11-Feb-12 06:52 AM
Do it like below way. which will allow only number, character and dot & comma


function Addressvalidation()
 {
  
  var Addr = document.getElementById("objaddr");
  var patternt = /^[A-Za-z0-9./,]+$/;
  if (!Patrn.test(Addr.value)) {
    alert("Not valid");
    return false;
  }
  else
    return true;
  }
</script>


<input type="text" value="" id="objaddr" onkeyup="Addressvalidation();" />
  chitra ganapathy replied to Sandeep Mittal
11-Feb-12 07:06 AM
thank u.... i want to add two textbox here...


var phn = document.getElementById('txtPhn'); how should i add
  R B replied to chitra ganapathy
11-Feb-12 07:11 AM

Hello,

 

<asp:TextBox ID="txtAlphaNumeric" runat="server" onkeydown = "return isAlphaNumeric(event.keyCode);" onpaste = "return false;"></asp:TextBox>

<script type="text/javascript">

 

    function isAlphaNumeric(keyCode) {

      return ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || keyCode == 188 || keyCode == 190 || keyCode == 191 || keyCode == 8)

    }                                          

 

</script>

 

 

Hope this is helpful !

Thanks

 

 

 

 

 

  chitra ganapathy replied to Sandeep Mittal
11-Feb-12 07:26 AM
need coding for accepting alphabets and -
  chitra ganapathy replied to R B
11-Feb-12 07:27 AM
need coding for accepting alphabets and -
  Sandeep Mittal replied to chitra ganapathy
11-Feb-12 07:45 AM
There is nothing to do with the below stament. I written this mistakenly
var phn = document.getElementById('txtPhn');

just add onkeypress event for the controls you want to validate
onkeypress="return validate(event)"
 
Example
<
asp:TextBox ID="Textbox1" onkeypress="return validate(event)" runat="server"></asp:TextBox>
<asp:TextBox ID="Textbox2" onkeypress="return validate(event)" runat="server"></asp:TextBox>

  R B replied to chitra ganapathy
11-Feb-12 08:01 AM

Hello,


in following function key code 189 for -
and key code 65 to 90 is for alphabet

Note :: pls added this function in textbox OnKeyDown javascript event as following way




<asp:TextBox ID="txtAlphaNumeric" runat="server" onkeydown = "return isAlphaNumeric(event.keyCode);" onpaste = "return false;"></asp:TextBox>

<script type="text/javascript">

 

    function isAlphaNumeric(keyCode) {

      return ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || keyCode == 188 || keyCode == 190 || keyCode == 191 || keyCode == 8

|| keyCode == 189

)

    }                                        

 

</script>

 

 

Hope this is helpful !

Thanks

Create New Account
help
a form in which i have a html table inside a div name age salary textbox textbox textbox textbox textbox textbox textbox textbox textbox textbox textbox textbox how to insert data into a table in sql server using
i m adding rows dynamically on add button click using javascript like: name age salary textbox textbox textbox(on add button click) textbox textbox textbox(on add button click) textbox textbox textbox(on add button click) there is also a delete button for each row to
regarding ((TextBox)LoginView1.FindControl("UserName")).Text Can I do string A = (( TextBox )LoginView1.FindControl( "UserName" )).Text ? So, it depends on where you call this line of code. TextBox textBox = (TextBox)LoginView1.FindControl( "UserName" ); if (textBox ! = null ) { string A = textBox.Text; } string A = ""; system.web.UI.webcontrol myControl = loginview1.findcontrol("username"); if ( (myControl ! = null) && (myControl GetType() = = TypeOf(TextBox)) ) a = mycontrol.text; I am still getting same error: Message: Exception of type 'System.Web
Gridview , the gridview have the columns Sr.No ItemName Rate Quantity Amount Total Label dropdownlist textbox textbox textbox textbox dropdownlist must be filled from items coming from database. . .when page loads only one row
string' and 'string' D: \ maddy \ travels \ Admin \ form_agent2.aspx.cs 235 30 D: \ maddy \ travels \ TextBox txusername = ( TextBox )row.FindControl( "txtusername" ); TextBox txaddress = ( TextBox )row.FindControl( "txtaddress" ); TextBox txmobilenumber = ( TextBox )row.FindControl( "txtmobilenumber" ); TextBox txdate = ( TextBox )row.FindControl( "txtdate" ); TextBox txnooftickets = ( TextBox )row.FindControl( "txtnooftickets" ); TextBox txamount = ( TextBox )row.FindControl( "txtamount