/    Sign up×
Community /Pin to ProfileBookmark

Hi guys,

I want to make a javascript with a regex that gives an alert when NOT entering the following (price) format:

XXXXX.XX

whereas the part before the comma is a number with 1-5 digits and the part after the comma a number from 1-2

alternatively the input can be just the part in front of the comma, but without the comma itself.

Cheers

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 24.2004 — [font=monospace]<input onchange="if(!/^d{1,5}(.d{1,2})?$/.test(this.value)) {alert(); this.value=''; this.focus()}" type="text">[/font]
Copy linkTweet thisAlerts:
@vacationrentalsauthorAug 24.2004 — Hi Charles,

Thanks for taking the time here. I need to put this in a document this way, but there is still an error and I can;t figuer it out:

<html>

<head>

<meta name="GENERATOR" content="Microsoft FrontPage 5.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>New Page 2</title>

<script language="JavaScript">

function checkRequired(recommend)

{

if(!/^d{1,5}(.d{1,2})?$/.test(recommend.value))

{

alert("Please enter your name.");

recommend.test.value='';

recommend.test.focus();

return false;

}


return true;

}


</script>

</head>

<body>

<form name="recommend">

<input name="test" onchange="javascript: checkRequired();" type="text" size="20">

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@steelersfan88Aug 24.2004 — With 2 hands:[code=php]<html>
<head>
<title>Example</title>
<script type="text/javascript">

function checkRequired(f) {
if(!/^d{1,5}(.d{1,2})?$/.test(f.value)) {
alert("Please enter your name.");
f.value='';
f.focus();
return false;
}
return true;
}

</script>
</head>

<body>
<form name="recommend">
<input name="price" onchange="checkRequired(this)" type="text" size="20">
</form>
</body>
</html>[/code]
Dr. Script
Copy linkTweet thisAlerts:
@vacationrentalsauthorAug 24.2004 — That did it. But the thanks goes to both posters.

take care.
Copy linkTweet thisAlerts:
@steelersfan88Aug 24.2004 — Charles and I have worked well together recently, so there will be no fight in taking the thanks fro meach other ?
×

Success!

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