views:

43

answers:

1

i have a textbox in asp.net form.... if i entered numbers not like 7 or 8 or 9, then script function should be araised with alert message.... how to achieve this.... that 7 or 8 or 9 are first digits in my texbox...

A: 

UPDATE:

var testValue = document.getelementbyid('<%= TEXT_BOX.ClientID %>').value;
var re = new RegExp('/^[7-9]/');
if (testValue.match(re))
    // SUCCESS
else
    // NO SUCCESS

Better solution is usage of RegexValidator with Regex /^[7-9]/ or something like that. It will generate javascript code automatically

VMAtm
Hi vmatm ,, i dont know what is clientid...
Ramakrishna
ClientId - id of your textbox on the pagehttp://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx
VMAtm
ok.. thanks.. only scripting , no validation controls... thats why i am trying on this
Ramakrishna
mobile no series should be start with 7 or 8 or 9... from 2nd digit also we can enter 7 or 8 or 9... isnt it. my question is , if the first digit is either 7, 8 or 9 then allow to enter another keycode.. if not alert('enter a valid mobile series')
Ramakrishna
Updated the answer
VMAtm
ya i used like this... testValue = document.getelementbyid('<%= TEXT_BOX.ClientID %>').value.charat(0); if(testvalue!=7 }else alert('no'); }
Ramakrishna
And it works? Then mark the answer :)
VMAtm