Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

counting phone numbers in a textarea

Posted on 2009-05-11
10
242 Views
Last Modified: 2013-12-24
Hi, experts.

i have one textarea in which i want to enter mobile numbers as 910989876660

i want to allow maximum of 10 mobile numbers in the textarea.

also i am trying to do a validation of these 10 mobile numbers in the textarea.

i have regular expression to test mobile number as:

^(91\s?\-?\s?)9\d\s?\-?\s?[1-9]{1}\d{7}$

is this possible, can u guys guide me how can i implement this.
0
Comment
  • 6
  • 3
10 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 24361537
The expression allows dashes and blanks in the phone number and your example does not contain such dashes and blanks. Do you want to allow dashes and blanks in one phnoe number?
Also state please what you expect as separator character for the multiple phone numbers. Do you have newline characters or comas or semicolons or something else as separators?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24361557
By the way, the expression allows only numbers with exactlly eleven digits where first three digits are 919 then followed by a non zero digit and followed by seven digits.

0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 125 total points
ID: 24361558
if you are validating user input on the server (after form submit), then you can do this:
[NOTE: i am no regex guru - don't blame me if your regex does not work (though it looks like it should...)! :) ]

<cfif structkeyexists(form, 'mobilenumbers')>
<cfif len(trim(form.mobilenumbers))>
  <cfif listlen(trim(form.mobilenumbers), chr(10)&chr(13)) gt 10>
    ... more than 10 lines in the textarea - do what you have to do with this...
  <cflese>
    <cfloop list="#trim(form.mobilenumbers)#" index="line" delimiters="#chr(10)&chr(13)#">
      <cfif len(trim(line)) AND isvalid('regex', trim(line), '^(91\s?\-?\s?)9\d\s?\-?\s?[1-9]{1}\d{7}$')>
        ...mobile number is valid - do whatever you need to do...
      <cfelse>
        ...mobile number not valid or line is empty - do whatever...
      </cfif>
    </cfloop>
  </cfif>
</cfif>

Azadi
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 27

Expert Comment

by:azadisaryev
ID: 24361573
PS:
i forgot to mention that my posted code assumes you require your users to enter one mobile number per line in your textarea.

if your requirements are different [i.e. you require a comma-separated list of numbers] - change all chr(10)&chr(13) to your required list delimiter(s) [i.e. ",;|"].

Azadi
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24361626
if you also want to check the number of lines (again, assuming you require one mobile number per line) in your textarea while the user is entering numbers, and alert when they reach 10, this Zvonko's old answer will help you (cheers, Zvonko!):

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21378738.html

Azadi
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24361864
<|:-)
0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 125 total points
ID: 24367398
Here my proposal:


<html>
<head>
<title>Zvonko &#42;</title>
<style>
#numlines {
  vertical-align: top;
  font: bold 12px Courier;
  color: cornflowerblue;
}
</style>
<script>
function countNum(theBox){
  var theValue = theBox.value;
  var theNums = [];
  theValue.replace(/\b(9109[1-9]\d{7})\b/g,function(a,n){theNums.push(n)});
  theNums = theNums.slice(0,10);
  document.getElementById("numlines").innerHTML = theNums.join("<br>");
  theBox.form.numlist.value = theNums.join(",");
}
</script>
</head>
<form>
<input type="text" name="numlist" >
<table><tr><td>
<textarea name="phonenum" onKeyUp="countNum(this)" cols="14" rows="10" >
</textarea>
</td><td id="numlines">
</td></tr></table>
<input type="submit" >
</form>
</body>
</html>

<|;-)

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24367429
Of course you make the numlist as input field type="hidden" and read only the correct entered numbers that user can see in the right table cell.
0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 31580403
Both worked
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24392980
You are welcome.
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DNS, website, godaddy 6 89
Systems talking to each other 5 141
Coldfusion : Unix Epoch Time 4 40
web & database SERVERS -- PHYSICAL & VM ? 5 72
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

840 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