fxuser Posted February 26, 2011 Share Posted February 26, 2011 What im trying to achieve is not to let the users enter spaces or new lines and send them to database via ajax.. so how can echo a message that the user must enter something when he enters just line breaks or spaces in a textarea? i tried checking if the textarea value is null , = "" or = " " but thats just not what i need... thanks Quote Link to comment https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/ Share on other sites More sharing options...
denno020 Posted February 26, 2011 Share Posted February 26, 2011 I don't know of the standard practice for this, but you could do an explod on the text area input, and see how big the resulting array is, using space as the delimeter. If there is two items in the array, then the use must have entered a space, otherwise if it's just one thing long, there is no spaces in there.. As for line breaks, I'm not sure.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/#findComment-1179950 Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2011 Share Posted February 26, 2011 Are you trying to prevent submission of the form if the field has nothing but spaces or line feeds? In other words, the user has to enter actual text? Quote Link to comment https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/#findComment-1180003 Share on other sites More sharing options...
fxuser Posted February 26, 2011 Author Share Posted February 26, 2011 Are you trying to prevent submission of the form if the field has nothing but spaces or line feeds? In other words, the user has to enter actual text? thats exactly what im trying to do. I don't know of the standard practice for this, but you could do an explod on the text area input, and see how big the resulting array is, using space as the delimeter. If there is two items in the array, then the use must have entered a space, otherwise if it's just one thing long, there is no spaces in there.. As for line breaks, I'm not sure.. Denno if i explode the string using space " " then the user can enter spaces between words in a single line so i dont get how this would work properly in my problem , also the user can enter twice or more times lines , what i want is to prevent the user from entering spaces only or lines only without a single letter. Quote Link to comment https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/#findComment-1180022 Share on other sites More sharing options...
Altrozero Posted February 26, 2011 Share Posted February 26, 2011 This should work if(empty(trim($value)) { //Made up of just white spaces } else { //Has other content } Quote Link to comment https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/#findComment-1180023 Share on other sites More sharing options...
Tonic-_- Posted February 26, 2011 Share Posted February 26, 2011 If you are looking to strip new lines from going into the database then something like this? $remove = str_replace("\n", " ", $string); It will strip new line breaks from the $string which will be your variable holding your textarea data. Quote Link to comment https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/#findComment-1180052 Share on other sites More sharing options...
fxuser Posted February 26, 2011 Author Share Posted February 26, 2011 If you are looking to strip new lines from going into the database then something like this? $remove = str_replace("\n", " ", $string); It will strip new line breaks from the $string which will be your variable holding your textarea data. i want to strip whitespaces and new lines when there is letter inside the textarea.. This should work if(empty(trim($value)) { //Made up of just white spaces } else { //Has other content } yeap it works but how can i make it work in javascript? this is what i got var string; function IsNumeric(input){ var RE = /^-{0,1}\d*\.{0,1}\d+$/; return (RE.test(input)); } function _empty(string){ string = $.trim(string); if(!IsNumeric(string)){ return string.length = -1; } return FALSE; } else if (_empty(msg)){ $('#error').show(); $('#error').html("Error."); } it seems to work but on the second click it doesnt recognise the value and i have to refresh.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/#findComment-1180060 Share on other sites More sharing options...
fxuser Posted February 28, 2011 Author Share Posted February 28, 2011 bump! it my request in last post needs to go to javascript section , please move it. Quote Link to comment https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/#findComment-1180717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.