• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

counting phone numbers in a textarea

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
Gurpreet Singh Randhawa
Asked:
Gurpreet Singh Randhawa
  • 6
  • 3
2 Solutions
 
ZvonkoSystems architectCommented:
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
 
ZvonkoSystems architectCommented:
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
 
azadisaryevCommented:
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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
azadisaryevCommented:
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
 
azadisaryevCommented:
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
 
ZvonkoSystems architectCommented:
<|:-)
0
 
ZvonkoSystems architectCommented:
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
 
ZvonkoSystems architectCommented:
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
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
Both worked
0
 
ZvonkoSystems architectCommented:
You are welcome.
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.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now