472,782 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

text select in textarea (regular expression)

is there any way to select and mark part of text in textarea by regular

i need to select the first string in textarea whitch is like xxxxx,xxx

where x is any character

Jul 23 '05 #1
1 3496
"Volt" wrote :
i need to select the first string in textarea whitch is like xxxxx,xxx

You can use ranges to retrieve and highlight text, but few browsers
support them, namely IE4+ and recent Gecko-based browsers; the
following should work on IE5.5+ and Mozilla; if you need to support
older IE then you'll have to emulate $x properties on RegExp.
<textarea rows="5" cols="60">
Here's a matched sequence : 12345,123
<input type="button"
onclick="match('\\d{5},\\d{3}', this.form.elements[0])">

<script type="text/javascript">
function match(pattern, textarea){

function makeMatcher(func){
return function(re, ta) {
return !!
new RegExp(re).exec(ta.value) &&
func(ta, RegExp["$`"].length, RegExp["$&"].length);

function moz_match(textarea, start, length){
var v=textarea.value;
textarea.setSelectionRange(start, start+length);
((v.substr(0, start).replace(/[^\n]/g, "").length-1)/
((v.replace(/[^\n]/g, "")).length))|0;
return true;

function ie_match(textarea, start, length){
var rng, corr=textarea.value.substr(0, start).
rng.moveStart("character", start-corr);
rng.moveEnd("character", length);
return true;

function dummy(){
return false;

match=textarea.setSelectionRange && makeMatcher(moz_match) ||
textarea.createTextRange && makeMatcher(ie_match) ||

return match(pattern, textarea);
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Gaze | last post by:
Hi, I use <textarea> input more than one paragraph to the database, whose field type is set to "text". Then I retrieve it to display in <textarea>, which is OK, paragraph by paragraph, but not...
by: Voetleuce en fênsievry | last post by:
Hello everyone. I'm not a JavaScript author myself, but I'm looking for a method to remove duplicate words from a piece of text. This text would presumably be pasted into a text box. I have,...
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript...
by: Sunil Kulkarni | last post by:
I need to validate my TextArea as follows: 1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS 2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW I need some kind of a JS validation for the same. I have tried...
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
by: JosAH | last post by:
Greetings, Introduction This week we start building Query objects. A query can retrieve portions of text from a Library. I don't want users to build queries by themselves, because users make...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.