Two js methods commonly used in registration pages

In website production, the functions of login and registration often appear, so it is also very important to judge their js. The frequently used methods are trim() and test() .

1. trim() is used to remove empty strings on the left and right sides of the string.  js does not support the trim() method by default, but firefox supports this method

Therefore, if you need to ensure browser compatibility, you need to use the wrapped method in Jquery $.trim(string);

2. test(string) is used to check whether a string matches a certain pattern 

var str = "Either measure the temperature with a bath";
var patt1 = new RegExp("measure");
var result = patt1.test(str); //If str contains text matching patt1, return true, otherwise return false
alert("return result"+result);//return result true

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327074428&siteId=291194637