I have a field set as number (num) for validation. The code below will only allow numbers to be accepted in the field.

I would like to modify it such that is MUST have at least two numbers and as many characters as the person wants to type.
Can it be done by manipuplating this code?
Thx

if (validateObject.type == "num" || validateObject.type == "string") {
if ((validateObject.type == "num" && validateObject.len <= 0) || (validateObject.type == "num" && isNaN(validateObject.val))) { errors += language['start'] + language['field'] + validateObject.HTMLname + language['require'] + language['num'] + "\n";

Recommended Answers

All 12 Replies

firstly, it would be helpful if you pasted the full function. anyways, try to do something like:
1. make sure the length is not less than 2, as you want atleast 2 numbers.
2. do something like:

for(i = 0; i < validateObject.length; i++){
     if (validateObject.charAt(i) < '0' && validateObject.charAt(i) > '9')
             {//increase error}
}

This way you can further put a condition where say, the length of the input is 5, if the errorCount is more than (length - 2), you print a message.

Hope this helps!! ;)

Not exactlywhat I mean...I think.
Heres the full code. You will easily see what I am trying to do.
In a nutshell, we have to ask form filler outer the names and ages of all in their household. Currently I had to do it in to fiedls but would like to do it in one test area. We would like to prevent garbage being submitted.
The key is force them to have at least one set of digits regprenting at tleast the submitter's age and also their name. It could be that there are 20 people in the family so they might enter toweny names followed by their ages.
Is there a better way to get the data from the submitter that the way I have done it below?

<?php

if(isset($_POST["Submit"]))
{
require("c:\php\includes\class.phpmailer.php");

$mail = new PHPMailer();

$toaddress = "xxxxxxxxxxxxxx";  //Change this to the email address you will be receiving your notices.
$mailhost = "xxxxxxxxxxxxxxxxxxxx";  //Change this to your actual Domain name.
$fromaddress = "xxxxxxxxxxxxxxxxxxxxxx";  //Change this to the email address you will use to send and authenticate with.
$frompwd = "zzzzzzzzzzz";  //Change this to the above email addresses password.
$subject = "Airedale 911 Application Form";  //Change this to your own email message subject.


$referredby = $_POST["Referredby"];
$fromname = $_POST["Name"];
$street = $_POST["Street"] ;
$city = $_POST["City"];
$state = $_POST["State"];
$zip = $_POST["Zip"];
$homephone = $_POST["Homephone"] ;
$workphone = $_POST["Workphone"];
$cellphone = $_POST["Cellphone"];
$rplyto = $_POST["Email"];
$family = $_POST["Family"];
$ages = $_POST["Ages"];
$sex = $_POST["Sex"] ;
$previouslyowned = $_POST["Previouslyowned"] ;
$whenpreviouslyowned = $_POST["Whenpreviouslyowned"] ;
$sexpreviouslyowned = $_POST["Sexpreviouslyowned"] ;
$otherbreeds = $_POST["Otherbreeds"] ;
$fateoflastdog = $_POST["Fateoflastdog"] ;
$lostadog = $_POST["Lostadog"] ;
$movegiveupdog = $_POST["Movegiveupdog"] ;
$otherpets = $_POST["Otherpets"] ;
$otherpetsages = $_POST["Otherpetsages"] ;
$otherpetsspayedneutered = $_POST["Otherpetsspayedneutered"] ;
$a = $_POST["A"] ;
$fencedinyard = $_POST["Fencedinyard"] ;
$kindoffence = $_POST["Kindoffence"] ;
$howhighfence = $_POST["Howhighfence"] ;
$sizeoffencedinarea = $_POST["Sizeoffencedinarea"] ;
$runofhouse = $_POST["Runofhouse"] ;
$allowedonfurniture = $_POST["Allowedonfurniture"] ;
$havebedandblanket = $_POST["Havebedandblanket"] ;
$dogbedinwhatroom = $_POST["Dogbedinwhatroom"] ;
$wherewillairedalesleep = $_POST["Wherewillairedalesleep"] ;
$hoursnoonehome = $_POST["Hoursnoonehome"] ;
$daysaweekalone = $_POST["Daysaweekalone"] ;
$whatroomabovetimes = $_POST["Whatroomabovetimes"] ;
$travelingwherewilldogstay = $_POST["Travelingwherewilldogstay"] ;
$familiardogcrate = $_POST["Familiardogcrate"] ;
$whenwheredogcrate = $_POST["Whenwheredogcrate"] ;
$reference1 = $_POST["Reference1"] ;
$reference2 = $_POST["Reference2"] ;
$vetinfo = $_POST["Vetinfo"] ;
$comments = $_POST["Comments"] ;







$msgbody = "Referred by  = " . $referredby
."<br>"
."Your Full Name  = " . $fromname
."<br>"
."Your Street Address  = " . $street
."<br>"
."City  = " . $city
."<br>"
."State  = " . $state
."<br>"
."Zip Code  = " . $zip
."<br>"
."Your home telephone number (xxx-xxx-xxxx) or (000000000000 for NA)  = " . $homephone
."<br>"
."Your work number (xxx-xxx-xxxx) or (000000000000 for NA) = " . $workphone
."<br>"
."Your cell phone number (xxx-xxx-xxxx) or (000000000000 for NA)  = " . $cellphone
."<br>"
."Email = " . $rplyto
."<br>"
."Please list the names of all family members (including yourself), live-in help, frequent visitors, etc  = " . $family
."<br>"
."Please list the ages of all family members (including yourself), live-in help, frequent visitors, etc<br>
(place 00 between ages)  = " . $ages
."<br>"
."Do you prefer a male or female Airedale?  = " . $sex
."<br>"
."Have you previously owned an Airedale?  = " . $previouslyowned
."<br>"
."When?  = " . $whenpreviouslyowned
."<br>"
."Male or Female?  = " . $sexpreviouslyowned
."<br>"
."What other dog breeds have you owned?  = " . $otherbreeds
."<br>"
."What happened to your last dog?  = " . $fateoflastdog
."<br>"
."Have you ever lost a dog other than through death? = " . $lostadog
."<br>"
."If you had to move, would you consider giving up your dog?  = " . $movegiveupdog
."<br>"
."What other pets do you currently have?  = " . $otherpets
."<br>"
."Their ages  = " . $otherpetsages
."<br>"
."Are they spayed/neutered?  = " . $otherpetsspayedneutered
."<br>"
."Are they currently licensed?  = " . $a
."<br>"
."Do you a fenced-in yard?  = " . $fencedinyard
."<br>"
."What kind of fence?  = " . $kindoffence
."<br>"
."How high is the fence?  = " . $howhighfence
."<br>"
."Size of fenced-in area?  = " . $sizeoffencedinarea
."<br>"
."Will your new Airedale have run of the house?  = " . $runofhouse
."<br>"
."Be allowed on the furniture?  = " . $allowedonfurniture
."<br>"
."Have his/her own dog bed and blankets?  = " . $havebedandblanket
."<br>"
."In what room will the dog bed be placed?  = " . $dogbedinwhatroom
."<br>"
."In what room will your new Airedale sleep?  = " . $wherewillairedalesleep
."<br>"
."How many hours at a time is no one at home?  = " . $hoursnoonehome
."<br>"
."How many days a week will your dog be left alone?  = " . $daysaweekalone
."<br>"
."In what room(s) will your dog be during the above times?  = " . $whatroomabovetimes
."<br>"
."When you travel, where will your dog stay?  = " . $travelingwherewilldogstay
."<br>"
."Are you familiar with a dog crate?  = " . $familiardogcrate
."<br>"
."When and where do you use one?  = " . $whenwheredogcrate
."<br>"
."Name, address, phone number  = " . $reference1
."<br>"
."Name, address, phone number  = " . $reference2
."<br>"
."Your veterinarian's name, address, phone number  = " . $vetinfo
."<br>"
."Comments  = " . $comments; 



$mail->IsSMTP();
$mail->Host = $mailhost;
$mail->SMTPAuth = true;
$mail->Username = $fromaddress;
$mail->Password = $frompwd;

$mail->From = $fromaddress;
$mail->FromName = $fromname;
$mail->AddReplyTo($rplyto); 
$mail->AddAddress($toaddress); 
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $msgbody;

if(!$mail->Send())



{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}
header('Location:http://www.airedale911.org/thankyou.html');
}

?>

<html>
 
<head>

<script language="JavaScript" src="validation.js"></script>


<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Jacob Hage (jacob@hage.dk) -->
<!-- Web Site:  http://www.hagedesign.dk -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function init() {
define('Referredby', 'string', 'Referred By');
define('Name', 'string', 'Name');
define('Street', 'string', 'Street');
define('City', 'string', 'City');
define('State', 'string', 'State');
define('Zip', 'num', 'Zip', 5);
define('Homephone', 'string', 'Home phone', 12);
define('Workphone', 'string', 'Work Phone', 12);
define('Cellphone', 'string', 'Cell Phone', 12);
define('Email', 'email', 'Email');
define('Family', 'string', 'Please list the names of all family members (including yourself), live-in help, frequent visitors, etc');
define('Ages', 'num', 'Please list the ages of all family members (including yourself), live-in help, frequent visitors, etc');
define('Whenpreviouslyowned', 'string', 'When?');
define('Otherbreeds', 'string', 'What other dog breeds have you owned?');
define('Fateoflastdog', 'string', 'What happened to your last dog?');
define('Lostadog', 'string', 'Have you ever lost a dog...?');
define('Movegiveupdog', 'string', 'If you had to move, would you consider giving up your dog?');
define('Otherpets', 'string', 'What other pets do you currently have?');
define('Otherpetsages', 'string', 'Their ages?');
define('Otherpetsspayedneutered', 'string', 'Are they spayed/neutered?');
define('A', 'string', 'Are they currently licensed?');
define('Fencedinyard', 'string', 'Do you have a fenced-in-yard?');
define('Kindoffence', 'string', 'What kind of fence?');
define('Howhighfence', 'string', 'How high is the fence?');
define('Sizeoffencedinarea', 'string', 'Size of fenced-in area?');
define('Dogbedinwhatroom', 'string', 'In what room will the dog bed be placed?');
define('Wherewillairedalesleep', 'string', 'In what room will your new Airedale sleep?');
define('Hoursnoonehome', 'string', 'How many hours at a time is no one at home?');
define('Daysaweekalone', 'string', 'How many days a week will your dog be left alone?');
define('Whatroomabovetimes', 'string', 'In what room(s) will your dog be during the above times?');
define('Travelingwherewilldogstay', 'string', 'When you travel, where will your dog stay?');
define('Whenwheredogcrate', 'string', 'When and where do you use one??');
define('Daysaweekalone', 'string', 'REFERENCE 1: Name, address, phone number:?');
define('Whatroomabovetimes', 'string', 'REFERENCE 2: Name, address, phone number:?');
define('Vetinfo', 'string', 'Your veterinarian name, address, phone number');
define('Comments', 'string', 'Comments');

}
//  End -->
</script> 




<style>
.mystyle {font-size:15px; font-weight:600; font-family:Arial, Helvetica, sans-serif; font-variant:normal; letter-spacing:normal; font-size-adjust:inherit}
TD.mystyle {font-size:15px; font-weight:600; font-family:Arial, Helvetica, sans-serif; font-variant:normal letter-spacing:normal; font-size-adjust:inherit}
TR TD.mystyle {font-size:15px; font-weight:600; font-family:Arial, Helvetica, sans-serif; font-variant:normal letter-spacing:normal; font-size-adjust:inherit}
TABLE TR TD.mystyle {font-size:15px; font-weight:600; font-family:Arial, Helvetica, sans-serif; font-variant:normal letter-spacing:normal; font-size-adjust:inherit}
DIV TABLE TR TD.mystyle {font-size:15px; font-weight:600; font-family:Arial, Helvetica, sans-serif; font-variant:normal letter-spacing:normal; font-size-adjust:inherit}
.style1 {
	color: #C66300;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 27px;
}
</style>



</script>
</head>



<BODY OnLoad="init()">


<H2 class="style1">ADOPTION APPLICATION FEEDBACK FORM</H2>


<DIV class="mystyle">





<form name="SendEmail01" method="post">

<table border=0>

<tr>
	<td class="mystyle">Referred by:</td>
	<td><input type="text" name="Referredby" size="30"></td>
</tr>
<tr>
	<td class="mystyle">Your Full Name:</td>
	<td><input type="text" name="Name" size="30"></td>
</tr>
<tr>
	<td class="mystyle">Your Street Address:</td>
	<td><input type="text" name="Street" size="30"></td>
</tr>
<tr>
	<td class="mystyle">City:</td>
	<td><input type="text" name="City" size="30"></td>
</tr>
<tr>
	<td class="mystyle">State:</td>
	<td><input type="text" name="State" size="30"></td>
</tr>





<tr>
	<td class="mystyle">Zip Code (5 digits only):</td>
	<td><input type="text" name="Zip" maxlength="5" size="6"></td>
</tr>
<tr>
	<td class="mystyle">Your home telephone number (xxx-xxx-xxxx) or (000000000000) for NA:</td>
	<td><input type="text" name="Homephone" maxlength="12" size="13"></td>
</tr>
<tr>
	<td class="mystyle">Your work number (xxx-xxx-xxxx) or (000000000000) for NA: </td>
	<td><input type="text" name="Workphone" maxlength="12" size="13"></td>
</tr>
<tr>
	<td class="mystyle">Your cell  number (xxx-xxx-xxxx) or or (000000000000) for NA:</td>
	<td><input type="text" name="Cellphone" maxlength="12" size="13"></td>
</tr>







<tr>
	<td class="mystyle">Email:</td>
	<td><input type="text" name="Email" size="30"></td>
</tr>
<tr>
	<td class="mystyle">Please list the names of all family members (including yourself), live-in help, frequent visitors, etc:</td>
	<td><textarea rows="4" name="Family" cols="30"></textarea></td>
</tr>
<tr>
	<td class="mystyle">Please list the ages of all family members (including yourself), live-in help, frequent visitors, etc:<br>
	(place 00 between ages)</td>
	<td><textarea rows="4" name="Ages" cols="30"></textarea></td>
</tr>
<tr>
	<td class="mystyle">Do you prefer a male or female Airedale?:</td>
	<td class="mystyle"><input type="radio" name="Sex" value="Male"> Male <br>
        <input type="radio" name="Sex" value="Female"> Female<br>
        <input type="radio" name="Sex" value="No preference" checked="checked"> No Preference<br>
    </td>
</tr>
<tr>
	<td>        </td>
</tr>
<tr>
	<td>        </td>
</tr>
<tr>
	<td class="mystyle">Have you previously owned an Airedale?:</td>
	<td class="mystyle"><input type="radio" name="Previouslyowned" value="Yes"> Yes <br>
        <input type="radio" name="Previouslyowned" value="No" checked="checked"> No <br>
    </td>
</tr>
<tr>
	<td class="mystyle">When?:</td>
	<td class="mystyle"><input type="text" name="Whenpreviouslyowned" size="30"></td>
</tr>
<td class="mystyle">Male or Female?:</td>
<td class="mystyle"><input type="radio" name="Sexpreviouslyowned" value="Male"> Male <br>
        <input type="radio" name="Sexpreviouslyowned" value="Female"> Female<br>
        <input type="radio" name="Sexpreviouslyowned" value="Both"> Both<br>
		 <input type="radio" name="Sexpreviouslyowned" value="N/A" checked="checked"> N/A<br>

</td>
<tr>
	<td class="mystyle">What other dog breeds have you owned?:</td>
	<td><input type="text" name="Otherbreeds" size="30"></td>
</tr>
<tr>
	<td class="mystyle">What happened to your last dog?:</td>
	<td><input type="text" name="Fateoflastdog" size="30"></td>
</tr>
<tr>
	<td class="mystyle">Have you ever lost a dog other than through death?:</td>
	<td><input type="text" name="Lostadog" size="30"></td>
</tr>

<tr>
	<td class="mystyle">If you had to move, would you consider giving up your dog?:</td>
	<td><input type="text" name="Movegiveupdog" size="30"></td>
</tr>
<tr>
	<td class="mystyle">What other pets do you currently have?:</td>
	<td><input type="text" name="Otherpets" size="30"></td>
</tr>

<tr>
	<td class="mystyle">Their ages:</td>
	<td><input type="text" name="Otherpetsages" size="30"></td>
</tr>

<tr>
	<td class="mystyle">Are they spayed/neutered?:</td>
	<td><input type="text" name="Otherpetsspayedneutered" size="30"></td>
</tr>

<tr>
	<td class="mystyle">Are they currently licensed?:</td>
	<td><input type="text" name="A" size="30"></td>
</tr>
<tr>
	<td class="mystyle">Do you a fenced-in yard?:</td>
	<td><input type="text" name="Fencedinyard" size="30"></td>
</tr>

<tr>
	<td class="mystyle">What kind of fence?:</td>
	<td><input type="text" name="Kindoffence" size="30"></td>
</tr>

<tr>
	<td class="mystyle">How high is the fence?:</td>
	<td><input type="text" name="Howhighfence" size="30"></td>
</tr>

<tr>
	<td class="mystyle">Size of fenced-in area?:</td>
	<td><input type="text" name="Sizeoffencedinarea" size="30"></td>
</tr>
<tr>
	<td class="mystyle">Will your new Airedale have "run of the house"?:</td>
	<td class="mystyle"><input type="radio" name="Runofhouse" value="Yes"> Yes <br>
        <input type="radio" name="Runofhouse" value="No" checked="checked"> No <br>
    </td>
</tr>


<tr>
	<td>        </td>
</tr>
<tr>
	<td>        </td>
</tr>
<tr>
	<td class="mystyle">Be allowed on the furniture?:</td>
	<td class="mystyle"><input type="radio" name="Allowedonfurniture" value="Yes"> Yes <br>
        <input type="radio" name="Allowedonfurniture" value="No" checked="checked"> No <br>
    </td>
</tr>
<tr>
	<td>        </td>
</tr>
<tr>
	<td>        </td>
</tr>
<tr>
	<td class="mystyle">Have his/her own dog bed and blankets?:</td>
	<td class="mystyle"><input type="radio" name="Havebedandblanket" value="Yes"> Yes <br>
        <input type="radio" name="Havebedandblanket" value="No" checked="checked"> No <br>
    </td>
</tr>

<tr>
	<td class="mystyle">In what room will the dog bed be placed?:</td>
	<td><input type="text" name="Dogbedinwhatroom" size="30"></td>
</tr>
<tr>
	<td class="mystyle">In what room will your new Airedale sleep?:</td>
	<td><input type="text" name="Wherewillairedalesleep" size="30"></td>
</tr>
<tr>
	<td class="mystyle">How many hours at a time is no one at home?:</td>
	<td><input type="text" name="Hoursnoonehome" size="30"></td>
</tr>
<tr>
	<td class="mystyle">How many days a week will your dog be left alone?:</td>
	<td><input type="text" name="Daysaweekalone" size="30"></td>
</tr>
<tr>
	<td class="mystyle">In what room(s) will your dog be during the above times?:</td>
	<td><input type="text" name="Whatroomabovetimes" size="30"></td>
</tr>
<tr>
	<td class="mystyle">When you travel, where will your dog stay?:</td>
	<td><input type="text" name="Travelingwherewilldogstay" size="30"></td>
</tr>
<tr>
	<td class="mystyle">Are you familiar with a dog crate?:</td>
	<td><input type="radio" name="Familiardogcrate" value="Yes"> <span class="mystyle">Yes</span> <br>
        <input type="radio" name="Familiardogcrate" value="No" checked="checked"> <span class="mystyle">No</span> <br>    </td>
</tr>
<tr>
	<td class="mystyle">When and where do you use one?:</td>
	<td><textarea rows="4" name="Whenwheredogcrate" cols="30"></textarea></td>
</tr>
<br><br>
<tr>
	<td class="mystyle">REFERENCES: Name, address, phone number:</td>
	<td><textarea rows="4" name="Reference1" cols="30"></textarea></td>
</tr>
<tr>
	<td class="mystyle">REFERENCES: Name, address, phone number:</td>
	<td><textarea rows="4" name="Reference2" cols="30"></textarea></td>
</tr>
<tr>
	<td class="mystyle">Your veterinarian's name, address, phone number:</td>
	<td><textarea rows="4" name="Vetinfo" cols="30"></textarea></td>
</tr>
<tr>
	<td class="mystyle">Comments:</td>
	<td><textarea rows="8" name="Comments" cols="30"></textarea></td>
</tr>
<tr>
	<td><input type="submit" name="Submit" value="Submit" onClick="validate();return returnVal;" value="Test fields"></td>
</tr>

</table>
</form>






</div>

</body></html>

Hope this example will give you some idea on how to validate fields' using regExp()...

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="#myStyle" media="all"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> 
<title>Validate the field</title>
<style id="myStyle" type="text/css">
/* <![CDATA[ */
@media screen { 
body {
     width: 100%;
     height: 100%;
     text-align: center;
     background-color: #fff;
     color: #000;
     font: 80% "Trebuchet MS", Arial, sans-serif;
} 

body #wrap {
     width: 80%;
     margin: 0% auto;
     padding: 0%;
     text-align: left;
}
div p {
     float: left;
}
div input[type="button"] {
     float: left;
     height: 13%;
     margin-top: 1%;
}
div input[type="text"] {
     width:30%;
     height: 13%;
     float: left;
     clear: left;
     margin: 1% 1% 0% 0%;
     padding: 0%;
}
}
/* ]]> */
</style>
<script type="text/javascript">
/* <![CDATA[ */
var validValue = /([\d]{2,10}[\w])|([\w][\d]{2,10})|([\w][\d]{2,10}[\w])/;
var input = document.getElementsByTagName('input');
function validate()
{ if (!validValue.test(input['txt'].value)) { alert('\nField must contain atleast two numeric value!','Invalid Entry') } else { alert('\nYour entry has been added!','Thank You'); }
}
function addEvent() {
if (document.addEventListener) 
input['btn'].addEventListener('click',validate,false);
else if (document.attachEvent)
input['btn'].document.attachEvent('onclick',validate);
}

if (window.addEventListener)
window.addEventListener('load',addEvent,false)
else if (window.attachEvent)
window.attachEvent('onload',addEvent)
else if (document.getElementById)
window.onload = addEvent;
/* ]]> */
</script>     
<meta http-equiv="content-type" content="application/xhtml+xml;charset=utf-8" /> 
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
 
</head> 
<body>  
<div id="wrap">
<p lang="en"> This demo will validate the field and alert the user when it gives a non-valid value. </p>  
<input type="text" class="input-field" id="txt" />
<input type="button" value="Generate" id="btn" />
</div> 
</body> 
</html>

Thank you. So this will not error out as long as one types alpha caracters and at least two number?

I'll have to give it a shot. Is this easily integrated into the big code that I showed you or will the entire form need to be rebult?
Thanks

Hi there!
Yes i believe that it can be easily associated with your codes. Try to look at some of my thread here, regarding about form validation.

Hi,
I tried out your code. What input did you use to test it. I tried
Tami 33
and it said I still needed two numeric values.
I'm looking to verify basically as much as possible at least one name and age is entered.
Thx

Based on my declaration with the regExp(), white-spaces are not allowed on this input. The possible combination for this input is Tami22, 22Tami and Ta22mi...
In this case you'll have to change the declaration of the regExp().
If you need some space between characters then you can apply this with the validValue variable. var validValue = /[\w\s][\d]{2,6}/; you may apply any combination depending on what data you need to gather. Hope this clear things up... Good day to you

Would it be asking too much to put in english waht this expression says...

/[\w\s][\d]{2,6}/;

Thanks. Oh, is there documentation that would further explain the options for the above type of expression?

I think I've mostly figured out the code
I've added white spaces to the ends of each option
/([\d]{2,10}[\w][/s])|([\w][\d]{2,10}[/s])|([\w][\d]{2,10}[\w][/s])/;
will the expression pass if there is no white space
for instance if someone enters
Tami33,Rocky34
or will there have to be a white space entered at the end of the above for the expression to pass validation?

/(/([\d]{2,10}[\w][/s])|([\w][\d]{2,10}[/s])|([\w][\d]{2,10}[\w][/s])|[\d]{2,10}[\w]|([\w][\d]{2,10})|([\w][\d]{2,10}[\w])/

or would I have to specify without white spaces too? This epxression could get really long depending on how complicated your requirements are, yes?
Thx

id say skip regular expressions as if your strin gis actually very long, its going to be quite a big expression. Also, you will not be able to count how many of the entered digits are numbers. Unless, you specify to the user where they need to put the numbers that is at the start or at the end, or something, regular wont do such a good job. Stick with a for loop and try to just count the number of occurances of numbers to be more than two. that should be sufficient to suit your need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.