Solved

counting phone numbers in a textarea

Posted on 2009-05-11
10
240 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

831 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