728x90

JavaScript 53

[JavaScript] BOM navigator객체

BOM (Browser Object Model) 웹브라우저에는 전역 콘텍스트 객체가 존재하는데, 그 객체가 window 객체입니다. window객체를 이용하는 프로그래밍을 BOM이라고 부릅니다. BOM 객체 종류 - window : BOM의 최상위 객체 - location : 웹 브라우저의 주소표시줄 객체 - screen : 운영체제 화면의 속성을 가진 객체 - history : 방문기록을 가진 객체 - navigator : 브라우저에 대한 정보를 가진 객체 - document : navigator객체 - 브라우저나, 운영체제(OS)에 대한 정보가 담겨있다. - 주로 호환성 문제 등을 위해 사용한다. - navigator객체는 window.navigator로 접근 가능하며 window는 생략할 수 있다...

JavaScript 2023.07.05

[JavaScript] PC / Mobile 디바이스 구분하기

01. navigator.userAgent를 이용하여 확인하는 방법 참고 👉 MDN | Navigator: userAgent property 🌵 예시 코드 function isMobile() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ); } if (isMobile()) { // 모바일일 경우 } else { // 모바일 외 } 🌵 예시 코드 function isMobile() { const userAgent = navigator.userAgent; if ( userAgent.match( /iPhone|iPod|Android|Windows CE|BlackBerry|Sym..

JavaScript 2023.07.05

[JavaScript] form 유효성 검사 정규식 모음

플래그 설명 g 전역 탐색 i 대소문자를 구분하지 않음 🌵 이메일 const regEmail = /^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i; 🌵 아이디 const regId = /^(?=.*[0-9]+)[a-zA-Z][a-zA-Z0-9]{5,10}$/g; 영문자로 시작하고, 5 ~ 10 길이의 영문자와 숫자의 조합 🌵 한글만 const regex = /[a-z0-9]|[ \[\]{}()?|`~!@#$%^&*-_+=,.;:\"'\\]/g; 🌵 영문 const regex = /[a-zA-Z]/g; 🌵 숫자만 const regNum = /[0-9]/g; 🌵 자음 / 모음 가능 const regex =..

JavaScript 2023.07.05
728x90