Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to ASP. Is there an input mask for input boxes in ASP?

Status
Not open for further replies.

yryan

Programmer
May 10, 2002
15
CA
I have an input box on a form that contains a phone number. Is there a way for the input to appear as (709)555-1212?

Thanks for your help!
 
You could always make 3 short textboxes that allow the length you want and only accept numbers.
 
How do I get it to only accept numbers?
 
if numeric("variable") = true then
'is a numeric value
else
'not a numeric value
end if

Mark
 
Once the page loads to the browser, ASP isn't the tool for controling the content. You need to use JavaScript.

If you want to let the user enter ANYTHING in the textbox, and then let the page go back to the server before processing (then you can use ASP). I wouldn't recommend this solution. Anytime you can move processing away from the server and onto the client is better for everyone.

The JavaScript forum will probably have a FAQ or something that can help you quickly.

Good luck. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
This is a simple page that has a form with an input box, and submit button. the form action calls the current page, formats the number (if it is a number) and displays it above the textbox if it is a 10 digit number it displays "(123)456-7890" if it is a 7 digit number it displays "123-4567"

<%

function phoneformat(phonenumber)
if isnumeric(phonenumber) then
if len(trim(phonenumber)) = 10 then phoneformat = &quot;(&quot; & mid(phonenumber,1,3) & &quot;)&quot; & mid(phonenumber,4,3) & &quot;-&quot; & mid(phonenumber,7,4)
else
if len(trim(phonenumber)) = 7 then
phoneformat = mid(phonenumber,1,3) & &quot;-&quot; & mid(phonenumber,4,4)
end if
end if
end if
end function

if request.form(&quot;submit&quot;) = &quot;submit&quot; then
response.write(phoneformat(request.form(&quot;unformnum&quot;)))
end if
%>

<html>
<body>
<form name = &quot;phonenumber&quot; method = &quot;post&quot; action = &quot;phone.asp&quot;>
<input type = &quot;textbox&quot; name = &quot;unformnum&quot;>
<input type = &quot;submit&quot; name = &quot;submit&quot; value = &quot;submit&quot;>
</form>
</body>
</html>
 
This is a simple page that has a form with an input box, and submit button. the form action calls the current page, formats the number (if it is a number) and displays it above the textbox if it is a 10 digit number it displays &quot;(123)456-7890&quot; if it is a 7 digit number it displays &quot;123-4567&quot;

<%

function phoneformat(phonenumber)
if isnumeric(phonenumber) then
if len(trim(phonenumber)) = 10 then phoneformat = &quot;(&quot; & mid(phonenumber,1,3) & &quot;)&quot; & mid(phonenumber,4,3) & &quot;-&quot; & mid(phonenumber,7,4)
else
if len(trim(phonenumber)) = 7 then
phoneformat = mid(phonenumber,1,3) & &quot;-&quot; & mid(phonenumber,4,4)
end if
end if
end if
end function

if request.form(&quot;submit&quot;) = &quot;submit&quot; then
response.write(phoneformat(request.form(&quot;unformnum&quot;)))
end if
%>

<html>
<body>
<form name= &quot;phonenumber&quot; method= &quot;post&quot; action=&quot;phone.asp&quot;>
<input type = &quot;textbox&quot; name = &quot;unformnum&quot;>
<input type = &quot;submit&quot; name = &quot;submit&quot; value = &quot;submit&quot;>
</form>
</body>
</html>
 
so glad that posted wrong twice.

if len(trim(phonenumber)) = 10 then
didn't word wrap like it was saposed to. sorry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top