Validating to accept both number and char but needing at least 2 digits

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Validating to accept both number and char but needing at least 2 digits

 
0
  #1
Dec 16th, 2008
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


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. if (validateObject.type == "num" || validateObject.type == "string") {
  3. 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";
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 106
Reputation: sid78669 is an unknown quantity at this point 
Solved Threads: 4
sid78669's Avatar
sid78669 sid78669 is offline Offline
Junior Poster

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #2
Dec 17th, 2008
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:
  1. for(i = 0; i < validateObject.length; i++){
  2. if (validateObject.charAt(i) < '0' && validateObject.charAt(i) > '9')
  3. {//increase error}
  4. }

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!!
Last edited by sid78669; Dec 17th, 2008 at 5:40 am. Reason: Forgot to close the code tag!! LOL
Live free.... Die Hard!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #3
Dec 17th, 2008
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?

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3.  
  4. if(isset($_POST["Submit"]))
  5. {
  6. require("c:\php\includes\class.phpmailer.php");
  7.  
  8. $mail = new PHPMailer();
  9.  
  10. $toaddress = "xxxxxxxxxxxxxx"; //Change this to the email address you will be receiving your notices.
  11. $mailhost = "xxxxxxxxxxxxxxxxxxxx"; //Change this to your actual Domain name.
  12. $fromaddress = "xxxxxxxxxxxxxxxxxxxxxx"; //Change this to the email address you will use to send and authenticate with.
  13. $frompwd = "zzzzzzzzzzz"; //Change this to the above email addresses password.
  14. $subject = "Airedale 911 Application Form"; //Change this to your own email message subject.
  15.  
  16.  
  17. $referredby = $_POST["Referredby"];
  18. $fromname = $_POST["Name"];
  19. $street = $_POST["Street"] ;
  20. $city = $_POST["City"];
  21. $state = $_POST["State"];
  22. $zip = $_POST["Zip"];
  23. $homephone = $_POST["Homephone"] ;
  24. $workphone = $_POST["Workphone"];
  25. $cellphone = $_POST["Cellphone"];
  26. $rplyto = $_POST["Email"];
  27. $family = $_POST["Family"];
  28. $ages = $_POST["Ages"];
  29. $sex = $_POST["Sex"] ;
  30. $previouslyowned = $_POST["Previouslyowned"] ;
  31. $whenpreviouslyowned = $_POST["Whenpreviouslyowned"] ;
  32. $sexpreviouslyowned = $_POST["Sexpreviouslyowned"] ;
  33. $otherbreeds = $_POST["Otherbreeds"] ;
  34. $fateoflastdog = $_POST["Fateoflastdog"] ;
  35. $lostadog = $_POST["Lostadog"] ;
  36. $movegiveupdog = $_POST["Movegiveupdog"] ;
  37. $otherpets = $_POST["Otherpets"] ;
  38. $otherpetsages = $_POST["Otherpetsages"] ;
  39. $otherpetsspayedneutered = $_POST["Otherpetsspayedneutered"] ;
  40. $a = $_POST["A"] ;
  41. $fencedinyard = $_POST["Fencedinyard"] ;
  42. $kindoffence = $_POST["Kindoffence"] ;
  43. $howhighfence = $_POST["Howhighfence"] ;
  44. $sizeoffencedinarea = $_POST["Sizeoffencedinarea"] ;
  45. $runofhouse = $_POST["Runofhouse"] ;
  46. $allowedonfurniture = $_POST["Allowedonfurniture"] ;
  47. $havebedandblanket = $_POST["Havebedandblanket"] ;
  48. $dogbedinwhatroom = $_POST["Dogbedinwhatroom"] ;
  49. $wherewillairedalesleep = $_POST["Wherewillairedalesleep"] ;
  50. $hoursnoonehome = $_POST["Hoursnoonehome"] ;
  51. $daysaweekalone = $_POST["Daysaweekalone"] ;
  52. $whatroomabovetimes = $_POST["Whatroomabovetimes"] ;
  53. $travelingwherewilldogstay = $_POST["Travelingwherewilldogstay"] ;
  54. $familiardogcrate = $_POST["Familiardogcrate"] ;
  55. $whenwheredogcrate = $_POST["Whenwheredogcrate"] ;
  56. $reference1 = $_POST["Reference1"] ;
  57. $reference2 = $_POST["Reference2"] ;
  58. $vetinfo = $_POST["Vetinfo"] ;
  59. $comments = $_POST["Comments"] ;
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. $msgbody = "Referred by = " . $referredby
  68. ."<br>"
  69. ."Your Full Name = " . $fromname
  70. ."<br>"
  71. ."Your Street Address = " . $street
  72. ."<br>"
  73. ."City = " . $city
  74. ."<br>"
  75. ."State = " . $state
  76. ."<br>"
  77. ."Zip Code = " . $zip
  78. ."<br>"
  79. ."Your home telephone number (xxx-xxx-xxxx) or (000000000000 for NA) = " . $homephone
  80. ."<br>"
  81. ."Your work number (xxx-xxx-xxxx) or (000000000000 for NA) = " . $workphone
  82. ."<br>"
  83. ."Your cell phone number (xxx-xxx-xxxx) or (000000000000 for NA) = " . $cellphone
  84. ."<br>"
  85. ."Email = " . $rplyto
  86. ."<br>"
  87. ."Please list the names of all family members (including yourself), live-in help, frequent visitors, etc = " . $family
  88. ."<br>"
  89. ."Please list the ages of all family members (including yourself), live-in help, frequent visitors, etc<br>
  90. (place 00 between ages) = " . $ages
  91. ."<br>"
  92. ."Do you prefer a male or female Airedale? = " . $sex
  93. ."<br>"
  94. ."Have you previously owned an Airedale? = " . $previouslyowned
  95. ."<br>"
  96. ."When? = " . $whenpreviouslyowned
  97. ."<br>"
  98. ."Male or Female? = " . $sexpreviouslyowned
  99. ."<br>"
  100. ."What other dog breeds have you owned? = " . $otherbreeds
  101. ."<br>"
  102. ."What happened to your last dog? = " . $fateoflastdog
  103. ."<br>"
  104. ."Have you ever lost a dog other than through death? = " . $lostadog
  105. ."<br>"
  106. ."If you had to move, would you consider giving up your dog? = " . $movegiveupdog
  107. ."<br>"
  108. ."What other pets do you currently have? = " . $otherpets
  109. ."<br>"
  110. ."Their ages = " . $otherpetsages
  111. ."<br>"
  112. ."Are they spayed/neutered? = " . $otherpetsspayedneutered
  113. ."<br>"
  114. ."Are they currently licensed? = " . $a
  115. ."<br>"
  116. ."Do you a fenced-in yard? = " . $fencedinyard
  117. ."<br>"
  118. ."What kind of fence? = " . $kindoffence
  119. ."<br>"
  120. ."How high is the fence? = " . $howhighfence
  121. ."<br>"
  122. ."Size of fenced-in area? = " . $sizeoffencedinarea
  123. ."<br>"
  124. ."Will your new Airedale have run of the house? = " . $runofhouse
  125. ."<br>"
  126. ."Be allowed on the furniture? = " . $allowedonfurniture
  127. ."<br>"
  128. ."Have his/her own dog bed and blankets? = " . $havebedandblanket
  129. ."<br>"
  130. ."In what room will the dog bed be placed? = " . $dogbedinwhatroom
  131. ."<br>"
  132. ."In what room will your new Airedale sleep? = " . $wherewillairedalesleep
  133. ."<br>"
  134. ."How many hours at a time is no one at home? = " . $hoursnoonehome
  135. ."<br>"
  136. ."How many days a week will your dog be left alone? = " . $daysaweekalone
  137. ."<br>"
  138. ."In what room(s) will your dog be during the above times? = " . $whatroomabovetimes
  139. ."<br>"
  140. ."When you travel, where will your dog stay? = " . $travelingwherewilldogstay
  141. ."<br>"
  142. ."Are you familiar with a dog crate? = " . $familiardogcrate
  143. ."<br>"
  144. ."When and where do you use one? = " . $whenwheredogcrate
  145. ."<br>"
  146. ."Name, address, phone number = " . $reference1
  147. ."<br>"
  148. ."Name, address, phone number = " . $reference2
  149. ."<br>"
  150. ."Your veterinarian's name, address, phone number = " . $vetinfo
  151. ."<br>"
  152. ."Comments = " . $comments;
  153.  
  154.  
  155.  
  156. $mail->IsSMTP();
  157. $mail->Host = $mailhost;
  158. $mail->SMTPAuth = true;
  159. $mail->Username = $fromaddress;
  160. $mail->Password = $frompwd;
  161.  
  162. $mail->From = $fromaddress;
  163. $mail->FromName = $fromname;
  164. $mail->AddReplyTo($rplyto);
  165. $mail->AddAddress($toaddress);
  166. $mail->IsHTML(true);
  167. $mail->Subject = $subject;
  168. $mail->Body = $msgbody;
  169.  
  170. if(!$mail->Send())
  171.  
  172.  
  173.  
  174. {
  175. echo "Message could not be sent. <p>";
  176. echo "Mailer Error: " . $mail->ErrorInfo;
  177. exit;
  178. }
  179. header('Location:http://www.airedale911.org/thankyou.html');
  180. }
  181.  
  182. ?>
  183.  
  184. <html>
  185.  
  186. <head>
  187.  
  188. <script language="JavaScript" src="validation.js"></script>
  189.  
  190.  
  191. <SCRIPT LANGUAGE="JavaScript">
  192. <!-- Original: Jacob Hage (jacob@hage.dk) -->
  193. <!-- Web Site: http://www.hagedesign.dk -->
  194.  
  195. <!-- This script and many more are available free online at -->
  196. <!-- The JavaScript Source!! http://javascript.internet.com -->
  197.  
  198. <!-- Begin
  199. function init() {
  200. define('Referredby', 'string', 'Referred By');
  201. define('Name', 'string', 'Name');
  202. define('Street', 'string', 'Street');
  203. define('City', 'string', 'City');
  204. define('State', 'string', 'State');
  205. define('Zip', 'num', 'Zip', 5);
  206. define('Homephone', 'string', 'Home phone', 12);
  207. define('Workphone', 'string', 'Work Phone', 12);
  208. define('Cellphone', 'string', 'Cell Phone', 12);
  209. define('Email', 'email', 'Email');
  210. define('Family', 'string', 'Please list the names of all family members (including yourself), live-in help, frequent visitors, etc');
  211. define('Ages', 'num', 'Please list the ages of all family members (including yourself), live-in help, frequent visitors, etc');
  212. define('Whenpreviouslyowned', 'string', 'When?');
  213. define('Otherbreeds', 'string', 'What other dog breeds have you owned?');
  214. define('Fateoflastdog', 'string', 'What happened to your last dog?');
  215. define('Lostadog', 'string', 'Have you ever lost a dog...?');
  216. define('Movegiveupdog', 'string', 'If you had to move, would you consider giving up your dog?');
  217. define('Otherpets', 'string', 'What other pets do you currently have?');
  218. define('Otherpetsages', 'string', 'Their ages?');
  219. define('Otherpetsspayedneutered', 'string', 'Are they spayed/neutered?');
  220. define('A', 'string', 'Are they currently licensed?');
  221. define('Fencedinyard', 'string', 'Do you have a fenced-in-yard?');
  222. define('Kindoffence', 'string', 'What kind of fence?');
  223. define('Howhighfence', 'string', 'How high is the fence?');
  224. define('Sizeoffencedinarea', 'string', 'Size of fenced-in area?');
  225. define('Dogbedinwhatroom', 'string', 'In what room will the dog bed be placed?');
  226. define('Wherewillairedalesleep', 'string', 'In what room will your new Airedale sleep?');
  227. define('Hoursnoonehome', 'string', 'How many hours at a time is no one at home?');
  228. define('Daysaweekalone', 'string', 'How many days a week will your dog be left alone?');
  229. define('Whatroomabovetimes', 'string', 'In what room(s) will your dog be during the above times?');
  230. define('Travelingwherewilldogstay', 'string', 'When you travel, where will your dog stay?');
  231. define('Whenwheredogcrate', 'string', 'When and where do you use one??');
  232. define('Daysaweekalone', 'string', 'REFERENCE 1: Name, address, phone number:?');
  233. define('Whatroomabovetimes', 'string', 'REFERENCE 2: Name, address, phone number:?');
  234. define('Vetinfo', 'string', 'Your veterinarian name, address, phone number');
  235. define('Comments', 'string', 'Comments');
  236.  
  237. }
  238. // End -->
  239. </script>
  240.  
  241.  
  242.  
  243.  
  244. <style>
  245. .mystyle {font-size:15px; font-weight:600; font-family:Arial, Helvetica, sans-serif; font-variant:normal; letter-spacing:normal; font-size-adjust:inherit}
  246. TD.mystyle {font-size:15px; font-weight:600; font-family:Arial, Helvetica, sans-serif; font-variant:normal letter-spacing:normal; font-size-adjust:inherit}
  247. 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}
  248. 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}
  249. 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}
  250. .style1 {
  251. color: #C66300;
  252. font-family: Arial, Helvetica, sans-serif;
  253. font-size: 27px;
  254. }
  255. </style>
  256.  
  257.  
  258.  
  259. </script>
  260. </head>
  261.  
  262.  
  263.  
  264. <BODY OnLoad="init()">
  265.  
  266.  
  267. <H2 class="style1">ADOPTION APPLICATION FEEDBACK FORM</H2>
  268.  
  269.  
  270. <DIV class="mystyle">
  271.  
  272.  
  273.  
  274.  
  275.  
  276. <form name="SendEmail01" method="post">
  277.  
  278. <table border=0>
  279.  
  280. <tr>
  281. <td class="mystyle">Referred by:</td>
  282. <td><input type="text" name="Referredby" size="30"></td>
  283. </tr>
  284. <tr>
  285. <td class="mystyle">Your Full Name:</td>
  286. <td><input type="text" name="Name" size="30"></td>
  287. </tr>
  288. <tr>
  289. <td class="mystyle">Your Street Address:</td>
  290. <td><input type="text" name="Street" size="30"></td>
  291. </tr>
  292. <tr>
  293. <td class="mystyle">City:</td>
  294. <td><input type="text" name="City" size="30"></td>
  295. </tr>
  296. <tr>
  297. <td class="mystyle">State:</td>
  298. <td><input type="text" name="State" size="30"></td>
  299. </tr>
  300.  
  301.  
  302.  
  303.  
  304.  
  305. <tr>
  306. <td class="mystyle">Zip Code (5 digits only):</td>
  307. <td><input type="text" name="Zip" maxlength="5" size="6"></td>
  308. </tr>
  309. <tr>
  310. <td class="mystyle">Your home telephone number (xxx-xxx-xxxx) or (000000000000) for NA:</td>
  311. <td><input type="text" name="Homephone" maxlength="12" size="13"></td>
  312. </tr>
  313. <tr>
  314. <td class="mystyle">Your work number (xxx-xxx-xxxx) or (000000000000) for NA: </td>
  315. <td><input type="text" name="Workphone" maxlength="12" size="13"></td>
  316. </tr>
  317. <tr>
  318. <td class="mystyle">Your cell number (xxx-xxx-xxxx) or or (000000000000) for NA:</td>
  319. <td><input type="text" name="Cellphone" maxlength="12" size="13"></td>
  320. </tr>
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. <tr>
  329. <td class="mystyle">Email:</td>
  330. <td><input type="text" name="Email" size="30"></td>
  331. </tr>
  332. <tr>
  333. <td class="mystyle">Please list the names of all family members (including yourself), live-in help, frequent visitors, etc:</td>
  334. <td><textarea rows="4" name="Family" cols="30"></textarea></td>
  335. </tr>
  336. <tr>
  337. <td class="mystyle">Please list the ages of all family members (including yourself), live-in help, frequent visitors, etc:<br>
  338. (place 00 between ages)</td>
  339. <td><textarea rows="4" name="Ages" cols="30"></textarea></td>
  340. </tr>
  341. <tr>
  342. <td class="mystyle">Do you prefer a male or female Airedale?:</td>
  343. <td class="mystyle"><input type="radio" name="Sex" value="Male"> Male <br>
  344. <input type="radio" name="Sex" value="Female"> Female<br>
  345. <input type="radio" name="Sex" value="No preference" checked="checked"> No Preference<br>
  346. </td>
  347. </tr>
  348. <tr>
  349. <td> </td>
  350. </tr>
  351. <tr>
  352. <td> </td>
  353. </tr>
  354. <tr>
  355. <td class="mystyle">Have you previously owned an Airedale?:</td>
  356. <td class="mystyle"><input type="radio" name="Previouslyowned" value="Yes"> Yes <br>
  357. <input type="radio" name="Previouslyowned" value="No" checked="checked"> No <br>
  358. </td>
  359. </tr>
  360. <tr>
  361. <td class="mystyle">When?:</td>
  362. <td class="mystyle"><input type="text" name="Whenpreviouslyowned" size="30"></td>
  363. </tr>
  364. <td class="mystyle">Male or Female?:</td>
  365. <td class="mystyle"><input type="radio" name="Sexpreviouslyowned" value="Male"> Male <br>
  366. <input type="radio" name="Sexpreviouslyowned" value="Female"> Female<br>
  367. <input type="radio" name="Sexpreviouslyowned" value="Both"> Both<br>
  368. <input type="radio" name="Sexpreviouslyowned" value="N/A" checked="checked"> N/A<br>
  369.  
  370. </td>
  371. <tr>
  372. <td class="mystyle">What other dog breeds have you owned?:</td>
  373. <td><input type="text" name="Otherbreeds" size="30"></td>
  374. </tr>
  375. <tr>
  376. <td class="mystyle">What happened to your last dog?:</td>
  377. <td><input type="text" name="Fateoflastdog" size="30"></td>
  378. </tr>
  379. <tr>
  380. <td class="mystyle">Have you ever lost a dog other than through death?:</td>
  381. <td><input type="text" name="Lostadog" size="30"></td>
  382. </tr>
  383.  
  384. <tr>
  385. <td class="mystyle">If you had to move, would you consider giving up your dog?:</td>
  386. <td><input type="text" name="Movegiveupdog" size="30"></td>
  387. </tr>
  388. <tr>
  389. <td class="mystyle">What other pets do you currently have?:</td>
  390. <td><input type="text" name="Otherpets" size="30"></td>
  391. </tr>
  392.  
  393. <tr>
  394. <td class="mystyle">Their ages:</td>
  395. <td><input type="text" name="Otherpetsages" size="30"></td>
  396. </tr>
  397.  
  398. <tr>
  399. <td class="mystyle">Are they spayed/neutered?:</td>
  400. <td><input type="text" name="Otherpetsspayedneutered" size="30"></td>
  401. </tr>
  402.  
  403. <tr>
  404. <td class="mystyle">Are they currently licensed?:</td>
  405. <td><input type="text" name="A" size="30"></td>
  406. </tr>
  407. <tr>
  408. <td class="mystyle">Do you a fenced-in yard?:</td>
  409. <td><input type="text" name="Fencedinyard" size="30"></td>
  410. </tr>
  411.  
  412. <tr>
  413. <td class="mystyle">What kind of fence?:</td>
  414. <td><input type="text" name="Kindoffence" size="30"></td>
  415. </tr>
  416.  
  417. <tr>
  418. <td class="mystyle">How high is the fence?:</td>
  419. <td><input type="text" name="Howhighfence" size="30"></td>
  420. </tr>
  421.  
  422. <tr>
  423. <td class="mystyle">Size of fenced-in area?:</td>
  424. <td><input type="text" name="Sizeoffencedinarea" size="30"></td>
  425. </tr>
  426. <tr>
  427. <td class="mystyle">Will your new Airedale have "run of the house"?:</td>
  428. <td class="mystyle"><input type="radio" name="Runofhouse" value="Yes"> Yes <br>
  429. <input type="radio" name="Runofhouse" value="No" checked="checked"> No <br>
  430. </td>
  431. </tr>
  432.  
  433.  
  434. <tr>
  435. <td> </td>
  436. </tr>
  437. <tr>
  438. <td> </td>
  439. </tr>
  440. <tr>
  441. <td class="mystyle">Be allowed on the furniture?:</td>
  442. <td class="mystyle"><input type="radio" name="Allowedonfurniture" value="Yes"> Yes <br>
  443. <input type="radio" name="Allowedonfurniture" value="No" checked="checked"> No <br>
  444. </td>
  445. </tr>
  446. <tr>
  447. <td> </td>
  448. </tr>
  449. <tr>
  450. <td> </td>
  451. </tr>
  452. <tr>
  453. <td class="mystyle">Have his/her own dog bed and blankets?:</td>
  454. <td class="mystyle"><input type="radio" name="Havebedandblanket" value="Yes"> Yes <br>
  455. <input type="radio" name="Havebedandblanket" value="No" checked="checked"> No <br>
  456. </td>
  457. </tr>
  458.  
  459. <tr>
  460. <td class="mystyle">In what room will the dog bed be placed?:</td>
  461. <td><input type="text" name="Dogbedinwhatroom" size="30"></td>
  462. </tr>
  463. <tr>
  464. <td class="mystyle">In what room will your new Airedale sleep?:</td>
  465. <td><input type="text" name="Wherewillairedalesleep" size="30"></td>
  466. </tr>
  467. <tr>
  468. <td class="mystyle">How many hours at a time is no one at home?:</td>
  469. <td><input type="text" name="Hoursnoonehome" size="30"></td>
  470. </tr>
  471. <tr>
  472. <td class="mystyle">How many days a week will your dog be left alone?:</td>
  473. <td><input type="text" name="Daysaweekalone" size="30"></td>
  474. </tr>
  475. <tr>
  476. <td class="mystyle">In what room(s) will your dog be during the above times?:</td>
  477. <td><input type="text" name="Whatroomabovetimes" size="30"></td>
  478. </tr>
  479. <tr>
  480. <td class="mystyle">When you travel, where will your dog stay?:</td>
  481. <td><input type="text" name="Travelingwherewilldogstay" size="30"></td>
  482. </tr>
  483. <tr>
  484. <td class="mystyle">Are you familiar with a dog crate?:</td>
  485. <td><input type="radio" name="Familiardogcrate" value="Yes"> <span class="mystyle">Yes</span> <br>
  486. <input type="radio" name="Familiardogcrate" value="No" checked="checked"> <span class="mystyle">No</span> <br> </td>
  487. </tr>
  488. <tr>
  489. <td class="mystyle">When and where do you use one?:</td>
  490. <td><textarea rows="4" name="Whenwheredogcrate" cols="30"></textarea></td>
  491. </tr>
  492. <br><br>
  493. <tr>
  494. <td class="mystyle">REFERENCES: Name, address, phone number:</td>
  495. <td><textarea rows="4" name="Reference1" cols="30"></textarea></td>
  496. </tr>
  497. <tr>
  498. <td class="mystyle">REFERENCES: Name, address, phone number:</td>
  499. <td><textarea rows="4" name="Reference2" cols="30"></textarea></td>
  500. </tr>
  501. <tr>
  502. <td class="mystyle">Your veterinarian's name, address, phone number:</td>
  503. <td><textarea rows="4" name="Vetinfo" cols="30"></textarea></td>
  504. </tr>
  505. <tr>
  506. <td class="mystyle">Comments:</td>
  507. <td><textarea rows="8" name="Comments" cols="30"></textarea></td>
  508. </tr>
  509. <tr>
  510. <td><input type="submit" name="Submit" value="Submit" onClick="validate();return returnVal;" value="Test fields"></td>
  511. </tr>
  512.  
  513. </table>
  514. </form>
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521. </div>
  522.  
  523. </body></html>
  524.  
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #4
Dec 17th, 2008
Hope this example will give you some idea on how to validate fields' using regExp()...

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?xml-stylesheet type="text/css" href="#myStyle" media="all"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <title>Validate the field</title>
  7. <style id="myStyle" type="text/css">
  8. /* <![CDATA[ */
  9. @media screen {
  10. body {
  11. width: 100%;
  12. height: 100%;
  13. text-align: center;
  14. background-color: #fff;
  15. color: #000;
  16. font: 80% "Trebuchet MS", Arial, sans-serif;
  17. }
  18.  
  19. body #wrap {
  20. width: 80%;
  21. margin: 0% auto;
  22. padding: 0%;
  23. text-align: left;
  24. }
  25. div p {
  26. float: left;
  27. }
  28. div input[type="button"] {
  29. float: left;
  30. height: 13%;
  31. margin-top: 1%;
  32. }
  33. div input[type="text"] {
  34. width:30%;
  35. height: 13%;
  36. float: left;
  37. clear: left;
  38. margin: 1% 1% 0% 0%;
  39. padding: 0%;
  40. }
  41. }
  42. /* ]]> */
  43. </style>
  44. <script type="text/javascript">
  45. /* <![CDATA[ */
  46. var validValue = /([\d]{2,10}[\w])|([\w][\d]{2,10})|([\w][\d]{2,10}[\w])/;
  47. var input = document.getElementsByTagName('input');
  48. function validate()
  49. { 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'); }
  50. }
  51. function addEvent() {
  52. if (document.addEventListener)
  53. input['btn'].addEventListener('click',validate,false);
  54. else if (document.attachEvent)
  55. input['btn'].document.attachEvent('onclick',validate);
  56. }
  57.  
  58. if (window.addEventListener)
  59. window.addEventListener('load',addEvent,false)
  60. else if (window.attachEvent)
  61. window.attachEvent('onload',addEvent)
  62. else if (document.getElementById)
  63. window.onload = addEvent;
  64. /* ]]> */
  65. </script>
  66. <meta http-equiv="content-type" content="application/xhtml+xml;charset=utf-8" />
  67. <meta http-equiv="Content-Style-Type" content="text/css" />
  68. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  69.  
  70. </head>
  71. <body>
  72. <div id="wrap">
  73. <p lang="en"> This demo will validate the field and alert the user when it gives a non-valid value. </p>
  74. <input type="text" class="input-field" id="txt" />
  75. <input type="button" value="Generate" id="btn" />
  76. </div>
  77. </body>
  78. </html>
Last edited by essential; Dec 17th, 2008 at 9:54 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #5
Dec 17th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #6
Dec 18th, 2008
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.
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #7
Dec 18th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #8
Dec 18th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #9
Dec 18th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Re: Validating to accept both number and char but needing at least 2 digits

 
0
  #10
Dec 18th, 2008
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC