Hello friends,
In the above example it searches the first letter in x and first letter in tt matches or not i think. But what i want is if x='tr' i want to match the string in tt is starting with the value in x or not?. There is another option to do like this is
By the above example we can do it when the search string we know, but the serach string is in a javascript variable, then how to do it?
Code:
var x = document.frm.test.value;
var patt = new RegExp(x, "i");
var tt = 'some text';
if(tt.match(patt))
{ alert('matched'); }
Code:
var patt = /^tr/;
var tt = 'some text';
if(tt.match(patt))
{ alert('matches'); }
Comment