Solved

counting phone numbers in a textarea

Posted on 2009-05-11
10
237 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
 
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
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 
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 15

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to Import and export files in WordPress. 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 : Click on Too…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now