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
2010-06-15 07:14:31
Hi vmatm ,, i dont know what is clientid...
Ramakrishna
2010-06-15 07:16:37
ClientId - id of your textbox on the pagehttp://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx
VMAtm
2010-06-15 07:18:45
ok.. thanks.. only scripting , no validation controls... thats why i am trying on this
Ramakrishna
2010-06-15 07:27:16
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
2010-06-15 07:41:09
Updated the answer
VMAtm
2010-06-15 08:24:34
ya i used like this... testValue = document.getelementbyid('<%= TEXT_BOX.ClientID %>').value.charat(0); if(testvalue!=7 }else alert('no'); }
Ramakrishna
2010-06-22 07:16:11
And it works? Then mark the answer :)
VMAtm
2010-06-22 08:40:50