Solved

counting phone numbers in a textarea

Posted on 2009-05-11
10
254 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
[X]
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
  • 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
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. …

705 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