Posts

Showing posts from September, 2020

date with month name format validation

 Get date with month name export   const   dateWithMonthName  = ( da )  =>  {    let   date  =  da    if  ( date  !==  null  &&  date  !==  ""  &&  date  !==  undefined ) {      date  =  new   Date ( da )      const   dateTimeFormat  =  new   Intl . DateTimeFormat ( 'en' , {  year :   'numeric' ,  month :   'long' ,  day :   '2-digit'  })      const  [{  value :  month  }, , {  value :  day  }, , {  value :  year  }] =  dateTimeFormat . formatToParts ( date )      return   ` ${ day }   ${ month }   ${ year } `   }  else  {      return   ""  ...

get Today Date Function , #get current date using javaScripts

 Today date Functions   export   function   getTodayDate () {    var   today  =  new   Date ();    var   dd  =  today . getDate ();    var   mm  =  today . getMonth () +  1 ;    var   yyyy  =  today . getFullYear ();    if  ( dd  <  10 ) {      dd  =  '0'  +  dd ;   }    if  ( mm  <  10 ) {      mm  =  '0'  +  mm ;   }    const   todayDAte  =  yyyy  +  '-'  +  mm  +  '-'  +  dd ;    return   todayDAte }   https://freecodesmasters.blogspot.com/2020/09/today-date-function.html

email validation regex #Email

 EMAIL VALIDATI ON REGEX   export   const   emailValidation  =  email   =>  {      const   regex  =  / ^ (([^ <>()[ \]\\ .,;:\s@" ] + ( \. [^ <>()[ \]\\ .,;:\s@" ] + ) * ) | ( ". + " )) @ (( \[ [ 0-9 ] {1,3}\. [ 0-9 ] {1,3}\. [ 0-9 ] {1,3}\. [ 0-9 ] {1,3}\] ) | (([ a-zA-Z\-0-9 ] +\. ) + [ a-zA-Z ] {2,} )) $ / ;      return   regex . test ( email . toLowerCase ()); }   Click here for share

Replace under scrore with space validation

 Replace under score with space validation   export   const   replaceUnderscoreWithSpace  =  name   =>  {      return   lowerCase ( name . split ( '_' ). join ( ' ' )); }   Click here for share

Replace space with UnderScrore validation

Replace space with Underscore validation     export   const   replaceSpaceWithUnderscore  =  name   =>  {      return   lowerCase ( name . split ( ' ' ). join ( '_' )); }     Click here for share

Alphabetic validation for React JS

 Alphabetic validation for React JS export   const   alphabeticStringValidation  =  val   =>  {      const   regex  =  / ^ [ A-Za-z\-_ ] + $ / ;   //substitute: /^[A-Za-z]+$/without letters      return   regex . test ( val ); }     Click here for Share

ZIP , postle validation #ZipCode validation

 Zip code validation export   const   zipCodeValidation  =  val   =>  {      const   regex  =  / ^ [ 0-9 ] + $ / ;      return  ( regex . test ( val ) &&  val . toString (). length  ===  6 ); } Click here for share  

Decimal number Validation

  Allow only decimal number validation   Click here for share link export   const   number  =  val   =>  {      const   regex  =  / ^ [ 0-9 ] + $ / ;      return   regex . test ( val ); }  

Mobile Number Regex #validationRegex #mobileNumber Validation

 mobile number validation regex  https://freecodesmasters.blogspot.com/2020/09/mobile-number-regex-validationregex.html export   const   mobileNumber  =  val   =>  {      const   regex  =  / ^ [ 0-9 ] + $ / ;      return  ( regex . test ( val ) &&  val . toString (). length  ===  10 ); }

string name validation #name validation #regex #

 Full name String values export   const   fullNameString  =  val   =>  {      const   regex  =  / ^ [ a-zA-Z ] +   [ a-zA-Z ] + $ / ;      return   regex . test ( val ); }

credit card format Regex for validation

  Credit Card validation regex export   const   ValidateCreditCardNumber  =  val   =>  {      var   visaRegEx  =  / ^ (?: 4 [ 0-9 ] {12} (?:[ 0-9 ] {3} ) ? ) $ / ;      var   masterCardRegEx  =  / ^ (?: 5 [ 1-5 ][ 0-9 ] {14} ) $ / ;      var   americaExpRegEx  =  / ^ (?: 3 [ 47 ][ 0-9 ] {13} ) $ / ;      var   discoverRegEx  =  / ^ (?: 6 (?: 011 | 5 [ 0-9 ][ 0-9 ])[ 0-9 ] {12} ) $ / ;      var   isValid  =  false ;      // test numbers      // 341140185346626.      // 375727641414391.      // 373834279838370.      // 348719775768795.      // 372653007683820.      if  ( visaRegEx . test ( val )) {...

Format mobile number to this format "(845) 963-2545" #mobileFormat

  // format phone number into foreign format default no:8459632545 format to = (845) 963-2545 // if mobile values is = 8459632545 export const   numberFormat = ( value )  =>  {      if  ( value  &&  value  !==  "" ) {          let   mobile  =  value.trim()          const   first  =  mobile . substr ( 0 ,  3 )          const   second  =  mobile . substr ( 3 ,  3 )          const   last  =  mobile . substr ( 6 ,  4 )          const   number  = ( `( ${ first } )  ${ second } - ${ last } ` )          return   number     }  else  {  ...

Load External Script into react when click events

 load external Script into React when any click events export   default   function   loadExternalScript ( scriptData ) {      return   new   Promise (( resolve ,  reject )  =>  {          const   scriptLoaded  =  document . getElementById ( scriptData . id );          // console.log('scriptLoaded', scriptLoaded);          if  ( scriptLoaded ) {              resolve ( true );         }  else  {              const   script  =  document . createElement ( 'script' );              script . async  =  true ;  ...

Impliment LocalStorage in ReactJs

 Local  Storage example with all method of it let   name  =  "jaypal" let   user_data  = { name : "jaypal"  ,  email : "parmarjaypal100@gmail.com"  ,  mobile : 259635874 } // set localStorage //first param is name of localStorage //second param is values of localStorage localStorage . setItem ( "userInfo"  ,  user_data ) //get localStorage value //get item used fro get values from localStorage localStorage . getItem ( "userInfo" ) // remove particular localStorage //set localStorage name localStorage . removeItem ( "userInfo" ) //remove all localStorage values  localStorage . clear () // Note: if you set values into object please use JSON.stringify() method   ex :  localStorage . setItem ( 'userInfo' , JSON...

apped data into object

  // first create Form Data object   const   formData  =  new   FormData ();      formData . append ( `steps[name]` , "jaypal");      formData . append ( `steps[ ${ Id } ]` , 1 );   // expected output  formData = {steps[name]:"jaypal", steps[id]:1}     

upload image into firebase and get image url from firebase in reactJs

// firebase object from your configurable data       var storageRef = firebase.storage().ref('/images/'+ url.name);       var uploadTask = storageRef.put(url);       uploadTask.on('state_changed', function(snapshot){          var progress =            (snapshot.bytesTransferred / snapshot.totalBytes) * 100;            switch (snapshot.state) {              case firebase.storage.TaskState.PAUSED:                console.log('Upload is paused');                break;              case firebase.storage.TaskState.RUNNING:                console.log('Upload is running');                break;        ...

Remove same Id or duplicate data from array

 let arrayFlat = [ {id:25 , name:"jaypal"}, {id:25 , name:"jaypal"}, {id:26 , name:"hello"}, {id:27 , name:"hi"} ]  const output = [...new Map(arrayFlat.map(o => [o.id, o])).values()] expected output:  let arrayFlat = [ {id:25 , name:"parmar"}, {id:26 , name:"hello"}, {id:27 , name:"hi"} ]

Image Preview Before upload image into ReactJs

 getInitialState: function(){   return{file: []} } _onChange: function(){   // Assuming only image   var file = this.refs.file.files[0];   var reader = new FileReader();   var url = reader.readAsDataURL(file);    reader.onloadend = function (e) {       this.setState({           imgSrc: [reader.result];       })     }.bind(this);   console.log(url) // Would see a path?   // TODO: concat files }, render: function(){  return(   <div>     <form>       <input          ref="file"          type="file"          name="user[image]"          multiple="true"         onChange={this_onChange}/>      </form>     {/* Only show first image, for now. */}     <img src={this.state...

search data from array using search method

                   filterUserData = [{name:"jaypal parmar" , firstName:"jaypal" , lastName:"parmar"}]                 filterUserData = filterUserData.filter(data=>{                     return(                         (data && data.firstName && data.firstName.toLowerCase().search(searchValue.toLowerCase()) !== -1 ) ||                         (data && data.lastName && data.lastName.toLowerCase().search(searchValue.toLowerCase()) !== -1 )                         )                 })          

String all word first character capitalization JavaScript function

 const capitalizeString = (values) => { //function values set initially     let str = values // split string word and create array      let data = str.split(" ") // create null array     let arrayJoin = [] // data push into array and perform all word first word capital     let co = data.map(data => {       arrayJoin.push(data.charAt(0).toUpperCase() + data.slice(1))     }) // combine array values into single string     let perfect = arrayJoin.join(" ")     return perfect   }