?
Solved

Convert a phonenumber, ssn no and a zip code entered in any valid format to numeric format

Posted on 2009-04-17
7
Medium Priority
?
565 Views
Last Modified: 2012-05-06
Hi!
In the code below, for txtTSYSPhone, the phone number entered in any of the below format
should be accepted: if the txt TSYSPhone is empty or contains less than 10 digits or is entered in the format 123-A56-7890 or 123a45g789 or the like, it should display an alert to enter a valid phone no.

(123)456-7890
123-456-7890
123.456.7890
123 456 7890
Or mix and match it, which would be unusual but still possible and accepted and should be
converted to the format 1234567890 and then matched with the value in the database, using ismatch function and tehn sent for further usage. Ismatch function is an internally written java script function in my application.
 Similarly for the zip code,
12345-6789
12345
12345 6789
should be accepted and then converted to the format 123456789 or 12345 and matched with the database value using the ismatch function and then sent for further usage.

Similarly, for the ssn no. or tax id,
123-45-6789 or
123 45 6789 or 123.45.6789 or mix or match of these patterns should be allowed to enter in the text box. If the text entered is empty or contains less than 9 digits or contains alphabetical characters, then an alert needs to be displayed and then converted to the format 123456789.
It should be matched with the value in the database using ismatch function and then sent for further usage.

I'm confused as to where this code need sto be inserted and what it should return.
ALL THE CODE FOR THIS NEEDS TO BE WRITTEN IN JAVASCRIPT.
i'M NOT USING ANY PROTOTYPES....NO PROTOTYPES SHOULD BE USED.

If I can get the EXACT logic/code that'll be great!
Thanks a million in advancE.

i'VE BEEN STRUGGLING FOR IT ALL THRU THE DAY.

IT'S EXTREMELY URGENT.




 


<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SearchTSYS.aspx.vb" Inherits="Blast2.SearchTSYS" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>TSYS Search</title>
    <link runat=server id=cssMaster type="text/css" rel=Stylesheet href="Styles\Master.css" />
    <link runat=server id=cssButtons type="text/css" rel=Stylesheet href="Styles\Round-Button.css" />
    
    <script language="javascript" src="Scripts/header.js"><!--//--></script>
	<script language="javascript" src="Scripts/common.js"><!--//--></script>
		
	<script type="text/javascript" language="javascript" src="callback\XMLHttpRequest.js"></script>
		
</head>
<body>
    <form id="formSearch" method="post" runat="server" onsubmit="fncPageValidate(); ">
    	<table cellspacing="1" cellpadding="1" border="0" align="center" Width="99%">
		<tr>
			<td width="20%">&nbsp;</td>
			<td align="right" valign="top"  width="20%">
			  <span class=button style="BACKGROUND-COLOR: transparent"><input onclick='window.close();' type=button value="Close" style="font-weight:bold;"></span>
			</td>
		</tr>
		</table>
		<%--<%If Request.RequestType = "GET" Then%>--%>
		<fieldset class="fieldset" style="width:500px;height:100px;" align="center">
		<legend class=heading2 align="center">TSYS Search<%If Request.RequestType = "POST" Then Response.Write("Results")%>
		</legend>
		<table cellspacing=2 cellpadding=2 border=0 class="table4" align="center" >
			<tr>
				<td style="width: 117px">Cust/Bus Phone:</td>
				<td>Tax ID/SS#:</td>	
							
				<td>Cust/Bus Name:</td>
				<td style="width: 121px">Cust/Bus Zip:</td>	
		   </tr>
		   <tr>
			    <td style="height: 12px; width: 117px;"><asp:LinkButton OnClientClick="javascript:PopulateTextBoxes();" ID="lbTSYSPhone" runat="server" Width="119px"></asp:LinkButton></td>
			    <td style="height: 12px"><asp:LinkButton OnClientClick="javascript:PopulateTextBoxes();" ID="lbTSYSID" runat="server" Width="115px"></asp:LinkButton></td>
			    
			    <td style="height: 12px"><asp:LinkButton OnClientClick="javascript:PopulateTextBoxes();" ID="lbTSYSName"  runat="server"  Width="119px"></asp:LinkButton></td>
			    <td style="height: 12px; width: 121px;"><asp:LinkButton OnClientClick="javascript:PopulateTextBoxes();" ID="lbTSYSZip"  runat="server" Width="119px"></asp:LinkButton></td>		    		  
		   </tr>			    			    			    
			<tr>
			<td style="width: 117px">
			<%--<div id="dTSYSPhone">	--%>	  	  
				<asp:TextBox ID="txtTSYSPhone" class="textbox1" maxlength="12" runat="server" Width="119px"></asp:TextBox>		
			<%--</div>	--%>
			</td>
				<td><asp:TextBox ID="txtID" class="textbox1" maxlength="20" runat="server"></asp:TextBox></td>	   
			    
				<td><asp:TextBox ID="txtTSYSName" class="textbox1" maxlength="36" runat="server"></asp:TextBox></td>
				<td ><asp:TextBox ID="txtZip" class="textbox1" maxlength="10" runat="server"></asp:TextBox></td>
			   </tr>
			   <tr>
				<td colspan="4" align="center">				
					<span class=button style="BACKGROUND-COLOR: transparent"><asp:Button OnClientClick="javascript:ShowLinks();" runat=server ID=butnGo Text="Go" Font-Bold=true/></span><%--&#160--%>
			    	<span class=button style="BACKGROUND-COLOR: transparent"><input onclick='formSearch.reset();' type=button value="Reset" style="font-weight:bold;"></span>
			    </td>			   
			   </tr>
		    </table>
		    <hr />
		    </fieldset>	
		    
		   <table border="0" width="99%">
			<tr class="title10">
			<td align=left>
				<a href="SearchTSYS.aspx?<%=Request.ServerVariables("query_string")%>"</a> 
				<%--style="font-size: 8pt; font-weight: bold;">Back To Search Screen</a>--%>
			</td>
			<td align=right>Total Records Found: <% if len(Total_Records) = 0 then response.write("0") else Response.write(Total_Records)%></td>
			</tr>
		   </table>
			<!-- ------------------------------------- -->
			<!-- TSYS Search Result -->
			<!-- ------------------------------------- -->
			<table cellspacing=2 cellpadding=2 border=0 class="table4" align="center" style="width: 494px" >
			<tr>
			   <td style="width: 502px">
		           <asp:datagrid enableViewState="false" CssClass="table11" id="dgTSYSSearch" runat="server" Width="100%" AutoGenerateColumns="False" >
		           <ItemStyle cssclass="dgheader4"></ItemStyle>
                   <AlternatingItemStyle cssclass="dgheader5"></AlternatingItemStyle>
		           <HeaderStyle cssclass="dgheader1"></HeaderStyle>
			       <Columns>
			            <asp:TemplateColumn HeaderText="Account #">
				            <ItemTemplate>
				               <asp:HyperLink runat="server" ID="hlAccountNumber" NavigateUrl="javascript:window.close();"></asp:HyperLink>
				            </ItemTemplate>
			            </asp:TemplateColumn>
			            <asp:BoundColumn DataField="Cardholder" HeaderText="C/B Name" />
			            <asp:BoundColumn DataField="Address_Line_1" HeaderText="P/B Name" />
			            <asp:BoundColumn DataField="Address_Line_2" HeaderText="Address" />
			            <asp:BoundColumn DataField="Identification_Number" HeaderText="ID #" />
			            <asp:TemplateColumn HeaderText="Status">
				        <ItemTemplate>
				            <asp:Label ID="lblStatus" runat="server"></asp:label></ItemTemplate>
			            </asp:TemplateColumn>
			          </Columns>
		         </asp:datagrid></td></tr>
			     <tr>
				   <td colspan="4" align="center">				
					 <span class=button style="BACKGROUND-COLOR: transparent"><input onclick='window.close();' type=button value="Close" style="font-weight:bold;"></span>
			       </td>			   
			     </tr>
			     <tr>
			        <td colspan="2" class="title10" align="center" height="36" valign="bottom">
		              <asp:Label ID="lblResult" Runat="server"></asp:Label>
			        </td>
			    </tr>
			
		</table>
		
		<%--<%end if%>		--%>
		
    </form>
 
		<script language=javascript>
		 
			var CMFormTpNo = "|11|12|13|15|16|19|23|";
 
			function editRequired () {
				formSearch.submit();
			}
				
			function redirect(acctNum){
				try {
					if (typeof(window.opener.document.location.href)!= 'undefined'){
						window.opener.document.location.href = 'acctinforequest.aspx?acctno='+ acctNum +'&resetforms=true'
						window.opener.document.all.tAcctNum.focus();
					}
				}catch(e){alert("Please make sure AIW screen is open.")}
 
				return;
			}		
 
		function fncPageValidate(){
				window.event.returnValue = false;
              
				with (document.all){		         
				      
					   
								
					 										
					if (typeof(txtID)=='object')
					   {
					  
						if(!IsMatch(txtID.value,'number' ))
						  {
							alert("Phone has to be a valid number.")
							txtID.value = ""
							txtID.focus();
							return;
							}
						
					   
						if(!IsMatch(txtTSYSPhone.value,"phone") 
				        {				       
						alert("Business Phone has to be a valid number with maximum of 10 							digits.")
						txtTSYSPhone.value = ""
						txtTSYSPhone.focus();
						;
						return;
						}
					  
                       
				        
					if(!IsMatch(txtzip.value,"zip")) {
							alert("Zipcode has to be a valid number with maximum of 5 								digits.")
							txtTSYSZip.value = ""
							txtZip.focus();
							return;
						}
						
						if (txtZip.value.length>0 && txtTSYSName.value.length<=0) 
						 {
							alert("Name field is required when zip code is entered.")
							txtZip.focus();
							return;
						}
					}
				}
				
				window.event.returnValue = true;
				
				ShowLinks();
			}
			
 
function PopulateTextBoxes()
{
   alert('test2')
  if(lbTSYSPhone.value.length > 0 )
  {
    txtTSYSPhone.value=lbTSYSPhone.value; 
  }
 
}
                
 
 
 
		//-->
		</script>	
			
			
			
			
		
    </body>
</html>

Open in new window

0
Comment
Question by:amukta
  • 4
  • 3
7 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24174293
amukta,

You want to use something like the following for a phone number field.

str = str.replace(/[^\d]/g,"");
if (!str.match(/^\d{10}$/)) alert("Please enter a valid number.");

In the code str should be the variable for the input field or have the value for the phone number.  Also you can change the 2nd line and have it do more than the alert.  Let me know if you have a question.

You don't want to use the method you are thinking of for an SSN or EIN.  Require the hypen since it is the only way you can know the type of ID number you get.  Don't be so allowing for that field if you will be getting input for SSN, EIN or other tax IDs.

Let me know if you have a question or need more info.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 

Author Comment

by:amukta
ID: 24177559
hI!

bUT THE REQUIREMENT IS AS SUCH FOR THE ZIP CODE, BUT FOR THE SSN NO. THE DOTS AN DSPACES CAN BE ENTERED , BUT SHOULD BE SENT TO DATABASE AS 123-45-6789 OT 123456789.
BUT FOR ZIP CODE IT HA STO BE EITHER 12345 OR 123456789 TO BE SENT TO DATABASE, BUT SPACES AND . ARE ACCEPTED FROM THE USERAND CONVERETD TO THE FORMAT OF THE DATABASE.

PLEASE LET ME KNOW, HOW THIS CAN BE DONE...asap.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24177736
DO NOT USE ALL CAPS!  Online it is like you are shouting or yelling and when used for all the post it is bad etiquette.
I don't really understand your response.  Please elaborate and reword it.  I overlooked that you asked about zip codes but I see no real response to what I did provide and said in my first post.  Please respond to what I have already said and provided.
What is the part about inserting in a DB?  Javascript can't insert directly in a DB on your server.  Also you should not rely on Javascript validation alone.  The formatting you describe for the info going in the DB should be done by server code.
If any part of what I provide isn't clear then please let me know.
bol
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:amukta
ID: 24178058
Hi!
The solution you gave me has partially resolved my question an dthat's why I didn't respond yet...don't get me wrong.
I'm not yelling at you.
If you are very particualr about not using capslock, then that's fine.
Forget about inserting it into the db, can u let me know, how it can be passed to the server side?
How can I remove the spaces, dots or any extra characters for the zip code entered in the following format?
12345-1234, 12345 1234, 12345. 1234, 12345/6789?

and also remove the above mentioned characters and any extra characters for the  ssn entered in the following format,

I'm asking these questions not because I want to just try, it's because my job requires those and also, I'm a beginner in Javascript.
Please let me know ASAP.

Thank you!

Thank you,
123.45.6789, 123 45 6789, 123/45/6789

and also
0
 

Author Comment

by:amukta
ID: 24178068
Hi!

The ssn can be entered any any other such possible formats.

Could u plz. get me the solution ASAP?
Thanks in advance.
0
 

Author Comment

by:amukta
ID: 24178074
I need to be completed with the above mentione dones before tomorrow evening. Please let me know teh solutions ASAP.
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 total points
ID: 24178329
The exact method I suggested for removing the non-digit characters from a phone number entry can be used to remove those from zip codes or even the SSN (although if you will allow other id numbers then I don't recommend removing the hypen but I mentioned this already).  Instead of str use the value for the zip code or SSN field.  If you want to just remove those other characters and get the digit only version then you can use something like  ...
return str.replace(/[^\d]/g,"");
Put it in a function or you can put it in an event and just set the form field's value to that new value.
Thanks for ditching the caps lock.  Trust me ... I am not the only one who would be bothered by it.  Now I do want you to stop with the ASAP requests.  Mention it once if you must but you need to remember all of us experts here are just volunteers.  It is VERY late where I live now and I won't be on tomorrow.  Including a "help ASAP" note in every post will just make this seem like work.  If you really need programming done on demand and all the work done for you by a schedule then you should hire a coder (which some of us even do on the side).  Let's keep EE just relaxing and casual.  If something is important and urgent mention it once and be generous with your points (and quick with the responses and details) and you will get the best results we can provide.
Let me know how that helps.  If you need help using the code in the other fields you have to provide details on your html and when you want this done.  Don't forget to have ASP code to back this up.  In my opinion it is waste to do this in Javascript.  Testing the input is good but don't format it when you will need to do it again on the server side.  Of course I am probably starting to sound like a broken record (I guess I am just hoping I will be heard on this VERY important point).
bol
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question