@@ -10,11 +10,35 @@ const countries = document.querySelector('#countries');
10
10
// paso 2
11
11
const usernameInput = document . querySelector ( '#username' ) ;
12
12
const emailInput = document . querySelector ( '#email' ) ;
13
+ const phoneCode = document . querySelector ( '#phone-code' )
13
14
14
15
// -- validaciones
15
16
let usernameValidation = false ;
17
+ let emailValidation = false ;
18
+ // let countriesValidation=false;
16
19
20
+ // paso3.1
21
+ // funcion para validacion estados input
17
22
23
+ const validacion = ( e , validacion , element ) => {
24
+
25
+ // const texto= usernameInput.parentElement.children[1]
26
+ const informacion = e . target . parentElement . children [ 1 ]
27
+
28
+ if ( validacion . value == '' ) {
29
+ element . classList . remove ( 'correct' )
30
+ element . classList . remove ( 'incorrect' )
31
+ informacion . classList . remove ( 'show-informacion' )
32
+ } else if ( validacion ) {
33
+ element . classList . add ( 'correct' )
34
+ element . classList . remove ( 'incorrect' )
35
+ informacion . classList . remove ( 'show-informacion' )
36
+ } else {
37
+ element . classList . add ( 'incorrect' )
38
+ element . classList . remove ( 'correct' )
39
+ informacion . classList . add ( 'show-informacion' )
40
+ }
41
+ }
18
42
19
43
// paso 1
20
44
[ ... countries ] . forEach ( option => {
@@ -23,24 +47,18 @@ let usernameValidation = false;
23
47
// paso 3
24
48
// estado
25
49
usernameInput . addEventListener ( 'input' , e => {
26
- // console.log(e.target.value);
27
-
28
50
usernameValidation = USERNAME_REGEX . test ( e . target . value )
29
- console . log ( usernameValidation ) ;
30
- const texto = usernameInput . parentElement . children [ 1 ]
31
- // const informacion= e.target.parentElement.children[1]
32
- console . log ( texto ) ;
33
- if ( usernameValidation . value == '' ) {
34
- usernameInput . classList . remove ( 'correct' )
35
- usernameInput . classList . remove ( 'incorrect' )
36
- texto . classList . remove ( 'show-informacion' )
37
- } else if ( usernameValidation ) {
38
- usernameInput . classList . add ( 'correct' )
39
- usernameInput . classList . remove ( 'incorrect' )
40
- texto . classList . remove ( 'show-informacion' )
41
- } else {
42
- usernameInput . classList . add ( 'incorrect' )
43
- usernameInput . classList . remove ( 'correct' )
44
- texto . classList . add ( 'show-informacion' )
45
- }
46
- } )
51
+ validacion ( e , usernameValidation , usernameInput ) //e= evento, usernameValidation =validacion ,usernameInput = input
52
+
53
+ } )
54
+
55
+ emailInput . addEventListener ( 'input' , e => {
56
+ emailValidation = EMAIL_REGEX . test ( e . target . value )
57
+ validacion ( e , emailValidation , emailInput )
58
+ } )
59
+ // paso3.2 evento para seleccionar el pais y codigo de telf
60
+ countries . addEventListener ( 'input' , e => {
61
+ const optionSelected = [ ... e . target . children ] . find ( option => option . selected ) ;
62
+ phoneCode . innerHTML = `+${ optionSelected . value } `
63
+ } )
64
+
0 commit comments