HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 30th, 2013, 08:52 AM
MikkM MikkM is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 MikkM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 41 m 31 sec
Reputation Power: 0
Limit what can be entered on text field.

Hello, i have a input form on my site.

Code:
<form method="post" action="Untitled-2.php">
<input name="search" style="font-size:110px" type="text" class="searchBox" size="700"   maxlength="6">
</form>


I managed to limit total length to 6 chars, but now i want to go deeper.

I want to let users to enter chars only in this format
"111AAA" that means 3 letters and 3 numbers and only this way , not AAA111 or 1A1A1A, only 111AAA

How can i achive this? Maybe javascript?


Best Regards
Mix

Reply With Quote
  #2  
Old January 30th, 2013, 10:03 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,879 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 7 h 20 m 28 sec
Reputation Power: 813
Hi,

if you actually want to enforce those restrictions, you need to validate the input on your server. HTML attributes or JavaScript can only be used to inform the user about errors and make the form more convenient.

Reply With Quote
  #3  
Old January 30th, 2013, 02:04 PM
MikkM MikkM is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 MikkM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 41 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
Hi,

if you actually want to enforce those restrictions, you need to validate the input on your server. HTML attributes or JavaScript can only be used to inform the user about errors and make the form more convenient.


What method is best to achive this? Maybe somehow check with php before form submiting?

I´m submiting my form like this:

PHP Code:
if (isset($_POST)) {
  if (isset(
$_POST["search"])){
    
$a $_POST['search'];
    echo 
$a;
    
//do something more 

Reply With Quote
  #4  
Old January 30th, 2013, 02:13 PM
notflip's Avatar
notflip notflip is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 148 notflip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 39 m 9 sec
Reputation Power: 1
You can also use jquery or javascript with a regular expression ( preg_match ) to check client side. Regular expressions are used to check for patterns and can check forvthe most complex patterns.

Reply With Quote
  #5  
Old January 30th, 2013, 05:26 PM
Catacaustic's Avatar
Catacaustic Catacaustic is offline
Code Monkey V. 0.9
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Location: A Land Down Under
Posts: 1,886 Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 15 h 12 m 20 sec
Reputation Power: 1798
Checking string length with PHP is simple.
PHP Code:
 $length strlen ($_POST['search']); 

Then you can check that the length is between whatever you need it to be.

Reply With Quote
  #6  
Old January 30th, 2013, 06:07 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,879 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 7 h 20 m 28 sec
Reputation Power: 813
Well, since you want a certain pattern, you can check that with a regular expression (like notflip already said):

The regular expression for a string of "three letters (a to z, A to Z) followed by three decimal digits" is
Code:
/^[a-z]{3}\d{3}$/i


So the PHP check would be
PHP Code:
if ( preg_match('/^[a-z]{3}\\d{3}$/i'$_POST['search']) )
    
// input matches
else
    
// input doesn't match 


Note that you don't need an explicit length check in this case, because it's implied by the pattern.

Reply With Quote
  #7  
Old May 7th, 2013, 04:07 AM
shellygill shellygill is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2013
Location: Ludhiana
Posts: 33 shellygill User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 47 m 53 sec
Warnings Level: 15
Number of bans: 1
Reputation Power: 0
you will need to use validations in your command as mentioned above by Jacques1.

Reply With Quote
  #8  
Old May 7th, 2013, 10:16 AM
coding1 coding1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2013
Posts: 11 coding1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 53 sec
Reputation Power: 0
Server side validation is the way to go. Use Jaques1 example.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > Limit what can be entered on text field.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap