473,699 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to restrict user not to post more character

123 New Member
i have a text box i mean textarea(<texta rea></textarea>)
in my page i want to restrict user no to post more than
40 character how can i do that
Oct 9 '09 #1
4 2264
Dormilich
8,658 Recognized Expert Moderator Expert
for 40 characters, it’s probably easier to use a text input field (use the maxlength attribute).
Oct 9 '09 #2
TheServant
1,168 Recognized Expert Top Contributor
What Dorm said, for step one. Text Area is really for larger lengths of text, while Text is for smaller (<255 ~my very flexible rule).

This can be bypassed by some less honourable people, so you should have server side checking as well. When you are processing the form, be sure to include a check using strlen().

Expand|Select|Wrap|Line Numbers
  1. if (strlen($_POST['myvar']) > 40) {
    echo "myvar too long, please keep it under 40 characters."; return;
    }
  2.  
Or something like that.
Oct 11 '09 #3
zorgi
431 Recognized Expert Contributor
Hm...
If it has to be done I would probably opt for the solution in javascript rather than php.

http://www2.psacake.com:81/web/js.asp
Oct 12 '09 #4
TheServant
1,168 Recognized Expert Top Contributor
@zorgi
Agreed, but if it is important (maybe it's not) javascript can also be bypassed with ease, so PHP should be used if any databases are involved and/or it's important to have restrictions on user input.

Never trust anyone. Forms should always be thoroughly checked for nasty code that people put in. Form submissions can be faked and javascript can be turned off. Thankfully, PHP is out of the users reach so should ultimately have the serious checks in.
Oct 12 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2096
by: tracy | last post by:
hi, I have a table name stud_info where we stored student's information. This is a sharing screen for Undergraduate department and Post graduate department. To differential a student type either in Undergraduate or Post graduate is using programme type; 1 is for Undergraduate and 2 for Post graduate ; Now, i want to restrict example, Undergraduate department to view,
3
2499
by: vijay21 | last post by:
hi all, Can we restrict the number of characters that the user can input in a javascript prompt? my browser hangs whenever i try to input more than 2048 characters in it. Thanks for any help
3
2489
by: Agnes | last post by:
In textbox, I know I can set e.handled = false in keypressevent , So I can restrict the user to input some invalid character or disallow the user to input any thing Now, in datagrid, there are 3 columns one is account code, 2nd is debit, 3rd is credit for some account code, (e.g bank) I want to allow the user to input both debit and credit column/ BUT for some account code( E.g salary) I want to disallow the user type anything in...
10
8889
by: sconeek | last post by:
hi all, i have a textfield where i would like the user to input only Y or N. can somebody tell me how can i restrict the user from entering any other character, number or special character. thanks.
12
2498
by: Me | last post by:
I'm trying to wrap my head around the wording but from what I think the standard says: 1. it's impossible to swap a restrict pointer with another pointer, i.e. int a = 1, b = 2; int * restrict ap = &a; int * restrict bp = &b;
21
6506
by: Niu Xiao | last post by:
I see a lot of use in function declarations, such as size_t fread(void* restrict ptr, size_t size, size_t nobj, FILE* restrict fp); but what does the keyword 'restrict' mean? there is no definition found in K&R 2nd.
2
2207
by: den 2005 | last post by:
Hi everybody, How do restrict entering these characters <>\"%';()& and telling user these caharcters are not allowed to be enter in the textbox field using RegularExpression Validator? I put in the Validation Expression property . It restrict every character execpt 0 to 9. How to fixed this? I used + in validation Expression property of Regular Expression Validator Control. All are working except when entering the character \, which...
5
8226
by: Dakrat | last post by:
Allow me to preface this post by saying that this is my first database project, and while I have learned a lot, any concepts I have learned are hit and miss as I have found new requirements and researched solutions. That said, I have a "training" database with PowerPoint briefings which I have users access and complete training. The form then records the date and time they completed training in a relevant field. I have a separate "master"...
4
1586
by: cyberlei | last post by:
like user have to type "A" for the first character in the blank bar,so how can i restrict the "A" for the first character in php string? Thank you
0
8706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8633
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8947
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5891
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.