Category: JavaScript
-
Removing array item and set state in React – functional version
The correct way is by using the array.filter method.
-
Error: ENOSPC: System limit for number of file watchers reached
The meaning of this error is that the number of files monitored by the system has reached the limit!!
Result: The command executed failed! Or throw a warning (such as executing a react-native start VSCode)
Solution:
Modify the number of system monitoring files
Ubuntu
sudo gedit /etc/sysctl.conf
Add a line at the bottom
fs.inotify.max_user_watches=524288
Then save and exit!
sudo sysctl -p
to check it
Then it is solved!
-
Gutenberg attributes to console
Log attributes to console using the following:
wp.data.select( 'core/block-editor' ).getSelectedBlock().attributes;
Source: https://notlaura.com/log-gutenberg-blocks-attributes-to-console/
-
JavaScript email validation
var emailreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,10})$/; if( emailreg.test( 'value_to_test_against' ) == false ) { //Email invalid }
-
Js/jQuery email validation
Using regular expressions
let email = jQuery('.nl-sub-email'); let emailReg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,10})$/; let errors = 0; if( ! email.val() || emailReg.test( email.val() ) == false ) { email.css('border', '1px solid red'); email.focus(); errors = 1; } else { email.css('border', '1px solid transparent'); errors = 0; }