/    Sign up×
Community /Pin to ProfileBookmark

characters search in input box

i am pretty new to javascript.

i have an input box that i would like to NOT allow urls or the consecutive letters “http” or “www” in.

is this possible?

thanks ahead of time

jason

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameApr 24.2009 — Yes it's possible through regEx. An example (with a bunch of added stuff, take or remove as wanted):

[code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>astupidtitle</title>

<script type="text/javascript">

function checkValue(form,input) {
var val = form[input].value;
//you might not need everything that's in rex, just threw in for example
var rex = /http|www.|.html|.htm|.php|.asp|.jpg|.gif|.wmv|.mpg|.flv|.swf|.txt|.css|.js/;
return !rex.test(val);
}

</script>
</head>
<body>
<form action="page2.html" name="someForm" onsubmit="return checkValue(this,'someInput');">
<p><a href="http://www.w3schools.com/js/js_obj_regexp.asp">Learn about regEx</a><br>
<a href="http://www.w3schools.com/jsref/jsref_obj_regexp.asp">Learn about RegExp object methods</a><br>
<a href="http://www.javascriptkit.com/jsref/regexp.shtml">Another excellent source for RegExp info</a><br><input type="text" name="someInput"><input type="submit" value="Submit"></p>
</form>
</body>
</html>[/code]
×

Success!

Help @jasoncstyle 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.19,
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,
)...