I have a textarea. I can figure out the number of characters in it as an when a user is typing in it.
I want the know the size of the textarea content in bytes thats going to take up on my server (MySQL db).
I need to know this on the client side before I insert into the db because I have to restrict to a size limit.
What/How will I need to check ?
1 char = 1 byte ?
Thanks
Size in bytes in textarea contents
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Well in which case I'd just go with:
If it's not accurate due to cross OS then the server will have to perform it checks.
Code: Select all
var size = textarea.value.length + 2; //Or whatever field type you're usingActually, a byte (by eight) is 8 bits .anjanesh wrote:A text file on my PC containing n characters is n bytes.
But this will vary on servers - if its 32-bit or 64-bit.
So, it doesn't matter if you have a register of 32bits or 64bits.
A byte remains 8 bits
But you are right if you say a character is usually saved in 7 or 8 bits (=1byte) (ascii).
However, nowadays, there are charsets that use more than one byte (multibyte) (eg: UTF-16)