Saturday, 25 March 2017

JS- Remove White space and retain New line character,spl char not allow

Javascript - Remove White space  and retain New line character,spl char not allow
===========================================================

function RemoveallSpaces() {
    var output = document.getElementById("content").value;          // textarea or text .....

    output = output.replace(/\s/g, "") // remove all spl characters

output = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(output)     //retain new line chars

    document.getElementById("output").innerHTML = output;
}


Direct second point

output = output.replace(/[ \t]/g,'');                              // textarea or text .....

function isValid(str){
return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);    //special character not allow 

}

No comments:

Post a Comment

KISS, DRY, SOLID, YAGNI — A Simple Guide to Some Principles of Software Engineering and Clean Code

1 — KISS (Keep It Simple, Stupid)  Simplicity triumphs over complexity. Direct and clear codes are better for developing, maintaining, and s...