/    Sign up×
Community /Pin to ProfileBookmark

i need to validate input on each line of a textarea

the user will input unlimited url’s each on a new line in a textarea
so…

[url]http://www…[/url]
[url]http://www….[/url]
.
.
.

I need to loop through each line to check the [url]http://[/url] has been inserted at the beginning of each new line

help please

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@QueryAug 18.2004 — Kaibobble,

Thinking about it, and this is pure speculation, your solution probably lies in using the subStr() function to parse through and break the entries up (google: javascript subStr)and chucking them into an array, and then using regular expression functionality (google: regular expressions javascript) to validate. this will probably require a evil, evil, evil, while() loop and result in one hell of a dirty hack! Unless their is a cleaner way to do this? Any other thoughts?

Best of luck, would be interested in the outcome!

Regards,

-Q
Copy linkTweet thisAlerts:
@kaibobbleauthorAug 18.2004 — i have it working by just using

if (urlstring.indexOf("http://")==-1)

where urlstring is the entire contents of the textarea.this only checks the first instance though. What i can't do is loop and split up the lines by /n to be able to check the beginning of each line
Copy linkTweet thisAlerts:
@BillyRayAug 18.2004 — This works for me - and automatically inserts "http://" at the start if it is missing:

<html>
<head>
<script type="text/javascript">
<!--
function checkEntries() {
var entryText = document.forms[0].elements['myTextArea'].value;
var entries = entryText.split('n');
for (var loop=0; loop<entries.length; loop++) {
if (entries[loop].indexOf('http://') != 0) entries[loop] = 'http://' + entries[loop];
}
document.forms[0].elements['myTextArea'].value = entries.join('n');
}
//-->
</script>
</head>

<body>
<form>
<textarea name="myTextArea" cols="40" rows="5"></textarea>
<br />
<input type="button" onclick="checkEntries();" value="Check entries" />
</form>
</body>
</html>


Hope this helps,

Dan
Copy linkTweet thisAlerts:
@kaibobbleauthorAug 18.2004 — thank you thank you - that has been doing my head in
Copy linkTweet thisAlerts:
@QueryAug 18.2004 — Kai,

Do you mind if I call you Kai? I don't know if this is do-able, search for textarea properties / attributes. If this fails, what I had in mind was somthing a bit more sinister, the subStr() function chops up strings, i.e. textarea.value. You use it by specifing a range, i.e. textarea.value.subStr(0,1). Now if you add the while loop to this mix, i.e. a=0; b=1; while(textarea.value.subStr(a,b)!=" ")

{

a++;

b++;

}

lines[..] = textarea.value.subStr(0,b);

the code above is non-functional and illustrates the concept, you will have to do a bit more work to get this going (like checking for two spaces in a row probably indicating end of input)but I'm reasonably confident that this is a way forward for you. I'm not sure if n will equate to " ", but you should be able to google your way through this.

Thoughts?

Regards,

-Q

Nice one BillyRay... Any ideas on OO javascript??
Copy linkTweet thisAlerts:
@BillyRayAug 18.2004 — Any ideas on OO javascript??[/quote]
Sure - what did you have in mind?

Dan
Copy linkTweet thisAlerts:
@QueryAug 18.2004 — BillyRay,

I posted a bit further down, [URL=http://]http://www.webdeveloper.com/forum/showthread.php?s=&threadid=42091[/URL] , would you mind having a look? Move your comments to that thread?

Thanks,

-Q
×

Success!

Help @kaibobble spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...