/    Sign up×
Community /Pin to ProfileBookmark

Learning how to validate

Yall~
I have ths code:

[code]
<form action=”/message_sent.php” onsubmit=”return validate(this);”>
<table width=”85%” border=”0″ height=”267″>
<tr>
<td width=”16%”>
<div align=”left”><font color=”#FFFFFF”><b>First Name:</b></font></div>
</td>
<td colspan=”2″>
<input type=”text” name=”name”>
</td>
</tr>
<tr>
<td width=”16%”>
<div align=”left”><font color=”#FFFFFF”><b>City:</b></font></div>
</td>
<td colspan=”2″>
<input type=”text” name=”city”>
</td>
</tr>
<tr>
<td width=”16%”>
<div align=”left”><font color=”#FFFFFF”><b>State:</b></font></div>
</td>
<td colspan=”2″>
<input type=”text” name=”state”>
</td>
</tr>
<tr>
<td width=”16%”>
<div align=”left”><font color=”#FFFFFF”><b>Message</b></font></div>
</td>
<td colspan=”2″>
<textarea name=”message” wrap=”VIRTUAL” cols=”50″ rows=”10″></textarea>
</td>
</tr>
<tr>
<td colspan=”2″>
<div align=”center”>
<input type=”submit” value=”Test” name=”submit”>[/code]

and was wondering how the best way to validate just those three things. I have a php that send it to me just can not figure out how to validate.

Thanks
The Devil

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@StashXJan 20.2005 — how you want to validate these inputs???
Copy linkTweet thisAlerts:
@Tasmanian_DevilauthorJan 20.2005 — StashX~

name just has letters and >0

city just has letter and >0

message to be >0

when submitted

Thanks

The Devil
Copy linkTweet thisAlerts:
@CharlesJan 20.2005 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

<style type="text/css">

<!--

fieldset {padding:1ex; width:20em}

label {display:block; text-align:right}

input, textarea {width:15em}

button {display:block; margin:auto; margin-top:1ex}

-->

</style>

<script type="text/javascript">

<!--

function require (f) {

var fields = ['name', 'city', 'message'];

var e, i = 0;

while (e = f.elements[fields[i++]]) {if (!/S/.test (e.value)) {alert (e.previousSibling.data + 'required'); return false}}

}

// -->

</script>

</head>

<body>

<form action="some-script.pl" onsubmit="return require (this)">

<fieldset>

<legend>Example</legend>

<label>Name <input name="name" type="text" onchange="if (!/^[a-z]*$/i.test(this.value)) {alert(); this.value = ''; this.focus()}"></label>

<label>City <input name="city" type="text" onchange="if (!/^[a-z]*$/i.test(this.value)) {alert(); this.value = ''; this.focus()}"></label>

<label>Message <textarea name="message"></textarea></label>

<button type="submit">Submit</button>

</fieldset>

</form>

</body>

</html>[/font]
×

Success!

Help @Tasmanian_Devil 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.18,
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,
)...