Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching brackets - can it be done with regular expressions?

Status
Not open for further replies.

AndyH1

Programmer
Jan 11, 2004
350
GB
I have a form with an input field in which I need to ensure that if a user enters an opening angular bracket there is also a matching closing one - ie <this is some text>ghsghgsh<this is some more>gshhsghsg. That is the number of opening brackets equals the number of closing.

Also I need to check that a closing one always follows an opening one, ie you don't get <hggshghdsg>jhjhj><<jhh>

I can program this obviously starting with a function to count the number of < brackets equals the number of closing >, but wondered if there is a more elegant way it can be done with regular expressions.

I have used regular expressions in the validation of other fields and the regular expression validator, but am by no means an expert and wondered if people could give me an opinion on whether it is possible, or am I just expecting too much - has anyone done anything similar and if so could they provide some pointers.

Thanks
Andy
 
regex would definitely work, however there are rich textbox plugins which do this work for you. If you continue rolling your own I would find a regex forum and ask them for assistance.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top