Create excel,Create CSV,pdf,xml file,Validate Email and Phone using Regex in coldfusion

Some tiny works in coldfusion for new programmers like create excel, pdf, and use of cfsavecontent,make first letter capital,Validate EmailID and Phone using regex etc.


<cfoutput>
    <!---Start : Make first letter capital of a name--->
      <cfset UserName = "pintu">
      #rereplace(UserName, '^(\w)(.*)', '\u\1\2')#
    <!---End : Make first letter capital of a name--->
 
 
    <!---Start: Create Excel File--->
      <cfsetting enablecfoutputonly="Yes">
      <cfcontent type="application/msexcel">
      <cfheader name="Content-Disposition" value="filename=FileName.xls">
      <!---Excel File Content--->
      <table border="0">
      <tr><td>Name</td><td>Marks</td></tr>
      <tr><td>AA</td><td>12</td></tr>
      <tr><td>BB</td><td>13</td></tr>
      <tr><td>CC</td><td>14></tr>
      <tr><td>DD</td><td>15</td></tr>
      </table>   
    <!---End: Create Excel File--->

<!---Start: Create CSV File--->
      <cfheader name="Content-disposition" value="attachment; filename=CsvFile.csv">
     <cfcontent type="text/csv">

      <!---CSV File Content--->
      UserSeq,Email Address,Results#CHR(13)#
     1,123,send#CHR(13)#
     2,123,failed#CHR(13)#
     3,123,received#CHR(13)#
     4,123,stop#CHR(13)#
    <!---End: Create CSV File--->


     <!---Start: Create PDF file--->
      <cfdocument format="Pdf" orientation="Portrait" backgroundvisible="true" pagetype="A4" fontEmbed = "yes">
         Pdf Content
      </cfdocument>
     <!---End: Create PDF file--->
   
   
  <!---Start : Save page output using cfsavecontent--->
  <cfcontent reset="true"><cfsavecontent variable="PageOutput">
    <cfoutput>
            Output content like html xml etc.
    </cfoutput>
  </cfsavecontent>
  <cffile action="write" file="rss.xml" output="#PageOutput#">   
  <!---End : Save page output using cfsavecontent--->

Validates User Email Address against possible illegal characters and Illegal structure

<cfset Input = 'pintukumar_2006@rediffmail.com'>
<cfset REStr = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,4}$">

<cfif REFind(REStr,Input) eq 1>
    Email Valid
<cfelse>
    Email Not Valid
</cfif>


Validates a 10 character string phone number against possible illegal characters and Illegal structure

<cfset InputPhone = '8802595134'>
<cfset REStrx = "^[1-9][0-9]{2}[1-9][0-9]{6}$" >
       
       
<cfif REFind(REStrx,InputPhone) eq 1>
     Phone Valid
<cfelse>
          Phone Not Valid
</cfif>

</cfoutput>

Comments

  1. A paid email service fee participants due to the fact that it delivers what cost-free providers can't: protection. That is why you must pay for e-mail. Consumers can easily count on that they possess control over who observes the information they deliver as well as receive, and also they don't need to fret about 3rd parties using their delicate relevant information.domain email finder

    ReplyDelete

Post a Comment

Popular posts from this blog

Login with facebook using coldfusion

Create CSV file in Coldfusion Using CFFile

Get Previous One Day Data in Sql Server