Question on Digits and Special Characters

K

Karen

Hi there,
in my asp form i would like to have a field which can ONLY accept
digits BUT can accept special characters as well such as: &,$$,##.
i.e: if the user enters :

147hhh, or P44556HH or QSSPE$% ---> this will be invalid
##123,45SS---> this is invalid
125&125#10$---> this is valid
12456--> this is valid too

is there any way to do this????

thanks!
 
H

HolaGoogle

i know that this is what i should do but how?? can you please give me a hint???
thanks for your quick answer
 
M

McKirahan

HolaGoogle said:
i know that this is what i should do but how?? can you please give me a hint???
thanks for your quick answer
"Kieran Dundon" <[email protected]> wrote in message


Are you looking for something like the following?

<html>
<head>
<title>hasLetter.htm</title>
<script language="javascript" type="text/javascript">
<!--
function hasLetter(str) {
var exp_letter = /[a-z]/i
if (exp_letter.test(str)) {
alert("'" + str + "' contains a letter.");
} else {
alert("'" + str + "' does not contain a letter.");
}
}
// -->
</script>
</head>
<body>
<form method="post" onsubmit="hasLetter(this.item.value)">
<input type="text" name="item" size="10" maxlength="10">
<input type="submit" value="Test"
</form>
</body>
</html>
 
M

McKirahan

Or would this be better?

<html>
<head>
<title>test.htm</title>
<script language="javascript" type="text/javascript">
<!--
function test(str) {
var rep = str.replace(/[0-9]/g,"");
rep = rep.replace(/[\#\$\&]/g,"");
if (rep == "") {
alert("'" + str + "' is valid.");
} else {
alert("'" + str + "' is invalid.");
}
}
// -->
</script>
</head>
<body>
<form method="post" onsubmit="test(this.item.value)">
<input type="text" name="item" size="10" maxlength="10">
<input type="submit" value="Go"
</form>
</body>
</html>

This removes all of the allowable characters and tests to see if the result
is non-blank.
 
H

HolaGoogle

Hi McKirahan,
thanks for your answers!! i know one of them is what i<m looking for
so let me try it and i<ll let you know!
thanks a lot you're wnderful!
McKirahan said:
Or would this be better?

<html>
<head>
<title>test.htm</title>
<script language="javascript" type="text/javascript">
<!--
function test(str) {
var rep = str.replace(/[0-9]/g,"");
rep = rep.replace(/[\#\$\&]/g,"");
if (rep == "") {
alert("'" + str + "' is valid.");
} else {
alert("'" + str + "' is invalid.");
}
}
// -->
</script>
</head>
<body>
<form method="post" onsubmit="test(this.item.value)">
<input type="text" name="item" size="10" maxlength="10">
<input type="submit" value="Go"
</form>
</body>
</html>

This removes all of the allowable characters and tests to see if the result
is non-blank.
 
H

HolaGoogle

Thanks a lot McKirahan...this is waht i was looking for. everything
works just fine!!!
Thanks Thanks Thanks a million !
have a nice week end!
McKirahan said:
Or would this be better?

<html>
<head>
<title>test.htm</title>
<script language="javascript" type="text/javascript">
<!--
function test(str) {
var rep = str.replace(/[0-9]/g,"");
rep = rep.replace(/[\#\$\&]/g,"");
if (rep == "") {
alert("'" + str + "' is valid.");
} else {
alert("'" + str + "' is invalid.");
}
}
// -->
</script>
</head>
<body>
<form method="post" onsubmit="test(this.item.value)">
<input type="text" name="item" size="10" maxlength="10">
<input type="submit" value="Go"
</form>
</body>
</html>

This removes all of the allowable characters and tests to see if the result
is non-blank.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top