Trim input field value to only alphanumeric characters/separate spaces with . with jQuery?

This is not really a jQuery question, it can be done with simple Javascript. First you need to lowercase the text, then replace spaces with periods, then remove non-alphanumeric.

This is not really a jQuery question, it can be done with simple Javascript. First you need to lowercase the text, then replace spaces with periods, then remove non-alphanumeric: var myStr = "Earth is 70% water, -! *#$^^ & 30% LAnd" myStr=myStr.toLowerCase(); myStr=myStr.

Replace(/ /g,". "); myStr=myStr. Replace(/^a-zA-Z0-9\.

+/g,""); This answer would leave multiple spaces as periods, as the user inputted. If you want it to match your answer (which actually condenses multiple spaces into one), then add on an extra replace: myStr=myStr. Replace(/\.

+/g, ". ").

Thank You Nguyen, works great:) – Maverick Jul 19 at 4:55.

Bind to the keyPress event and cancel out non alpha numeric chars. Sample code: $("#target"). Keypress(function(event) { var key = event.

Which; var keychar = String. FromCharCode(key).toLowerCase(); // allow control keys if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) return true; if ((("abcdefghijklmnopqrstuvwxyz0123456789"). IndexOf(keychar) == -1)) event.preventDefault(); return false; } }).

I'm trying to take just the value with any characters and clean it up if that makes sense – Maverick Jul 19 at 3:29 Yes. If you're looking at just cleaning up values, then use @Nguyen's regex replace method. – Mrchief Jul 19 at 3:34 Yup, Nguyen's regex was flawless:) With your masking method, what if the value was copy/pasted instead of typed/keypressed in?

– Maverick Jul 19 at 4:56 copy paste can be handled too by bindimg to 'paste' event. – Mrchief Jul 19 at 5:06.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions