Skip to content

Instantly share code, notes, and snippets.

View mbparvezme's full-sized avatar

M B Parvez (Ron) mbparvezme

View GitHub Profile
@mbparvezme
mbparvezme / clicked-outside-the-target.js
Last active March 4, 2024 07:27
This code will check whether you clicked inside the target or not
var targetElem = document.querySelector("#sidebar");
window.addEventListener('click',function(e){
if( !targetElem.contains(e.target) && (!document.getElementById('navSwitch').contains(e.target))){
$(targetElem).removeClass('open')
}
})
$testUsername = "https://twitter.com/webdevronsocial";
$regEx = '/(?:https?:\/\/)?(?:www\.)?twitter\.com\/(?:#!\/)?@?([a-zA-Z0-9_]{1,15})/';
if( preg_match( $regEx, $testUsername, $matches ) ){
/**
This is valid, play your code here
- $matches[0] will returns the profile URl
- $matches[1] will returns the Username
*/
}
$testUsername = "webdevronsocial";
$regEx = '/^@?([a-zA-Z0-9_]{1,15})$/';
if( preg_match( $regEx, $testUsername ) ){
/* This is valid, play your code here */
}