thanawala27
Newbie
22 Posts May 21st, 2007
08:10 PM
#1
Parse a textbox
--------------------------------------------------------------------------------
Hi,
I had a Question!
i have a textbox, where i have filled some value.
say "ABBC2122"
now i want to check whether the value entered starts with ABBC or not.
In short, I want to parse the Value of the textbox and match it with another string.
Any Advice will be appreciated
Thanks
Ravi
--------------------------------------------------------------------------------
Reply
r035198x
Admin
4,690 Posts Yesterday
06:15 AM
#2
Re: Parse a textbox
--------------------------------------------------------------------------------
Quote:
Originally Posted by thanawala27
Hi,
I had a Question!
i have a textbox, where i have filled some value.
say "ABBC2122"
now i want to check whether the value entered starts with ABBC or not.
In short, I want to parse the Value of the textbox and match it with another string.
Any Advice will be appreciated
Thanks
Ravi
I think there's a startsWith method that you can use, otherwise a simple regular expression will work for you.
--------------------------------------------------------------------------------
Report Reply
gits
Member
41 Posts Yesterday
06:33 AM
#3
Re: Parse a textbox
--------------------------------------------------------------------------------
yep ... an easy way would be to use an RegEx ... have a look at the following example:
Code: ( javascript )
// your textbox-value
var foo = "ABBC2122";
// test it with a simple RegEx - i use the literals here and call the testmethod
// instantly on var foo
var check = /^ABBC/.test(foo);
// check is now true ;)
// you may also use the constructor for the RegEx and ref it with a variable
// for later reuse and/or !! if you want to create a RegEx with a variable
// new RegExp(yourvar, options)
var re = new RegExp('^ABBC');
// now we use re and call the testmethod
check = re.test(foo);
// of course: check is true again
hope this helps ... and kind regards
--------------------------------------------------------------------------------
Report Reply
thanawala27
Newbie
22 Posts Today
02:11 PM
#4
Re: Parse a textbox
--------------------------------------------------------------------------------
hey guys,
thanks for ur replies
Gits, i tried wot u said, n yes it worked..
now i met with another issue..
now i want the end a string with 5 digits
so my valid string shud be "ABBC65278"...
ABCC shud be followed by only 5 digits....anything else is an invalid string
i think we need ot break the string for this...break the first 4 and the last 5...then do the checking...
can u guys help me out here
Thanks
Ravi