Showing posts with label javaScript. Show all posts

regexp: Java script Regular Expression bundle

What is Regular Expression?
Regular expression is machine language. It filter given input based on regular expression. For more information on regular expression read


Introducing the javascript bundle that contains bunch of useful Regular expression. I implemented some general regular expression in the javascript however there are tons of other reg exp still pending.

Current version regexp.0.0.1.js

  • Regular Expression Email 
  • Regular Expression hashtag
  • Regular Expression bold 
  • Regular Expression italic
  • Regular Expression strike
  • Regular Expression phone_3_3_4
  • Regular Expression phone_3_7
  • Regular Expression phone_10
  • Regular Expression phone_5_6
  • Regular Expression ipAddress
  • Regular Expression YYYY/MM/DD
  • Regular Expression MM/DD/YYYY
  • Regular Expression DD/MM/YYYY
  • Regular Expression Digit
  • Regular Expression Float
  • Regular Expression username
  • Regular Expression password
  • Regular Expression HEXcolor
  • Regular Expression imageFile
  • Regular Expression documentFile
  • Regular Expression HTMLtag
  • Regular Expression 12Hour
  • Regular Expression 24Hour
  • Regular Expression MAC
  • Regular Expression url
  • Regular Expression badWords

I request you to all reader to contribute for the javascript. Submit your regular expression:
- Submit your regular expression in comment
- Use Github :
- Join Google Plus community :
        - Submit Regular Expression, Request Regular Expression, Report bug, Discussion
- Download :

Getting started with JSON and Java Web application

What is JSON?
JSON stands for JavaScript Object Notation. Its text-based open standard designed for human-readable data interchange. To know more about JSON read the wikipedia . Here is how JSON object holds the data.

    "firstName": "Vicky",
    "lastName": "Thakor",
    "age": 25,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": 10021
    "phoneNumber": [
            "type": "home",
            "number": "212 555-1234"
            "type": "fax",
            "number": "646 555-4567"

Why use JSON in java web-application?
Its time to develop web-application that perform operation faster. Say if you want to process data without refreshing current page/content JSON is perfect solution for you. I'm going to show you quick demo with validating the email.

Download the JSON library for Java from sourceforge

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Validate Email Address</title>
        <input name="email" id="email"/>
        <span id="result"></span>
        <input type="button" value="check" id="check"/>
        <script src="../staticCDN/js/jquery-1.8.2.min.js"></script>
                var emailID = $("#email").val();
                    var obj = eval ("(" + data + ")");
                    var status = obj.status;
                        $("#result").html("Email is Okay!");
<%@page import="org.json.JSONObject"%>
<%@page import="javaQuery.validation.validate"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
String email = request.getParameter("email");
validate vEmail = new validate();
JSONObject status = new JSONObject();
    status.put("status", "SUCCESS");
    status.put("notify_error", "Email is Okay!");
    status.put("status", "FAIL");
    status.put("notify_error", "Provide valid email!");

Hope you get proper idea of JSON by checking all above codes. If you have any problem let me know.
Output of Demo:


Turn urls into links in text with jQuery, Java Script



Web Technology getting way much faster and easier. jQuery is the Advance version of javascript. jQuery's tag line says it self "Write less, do more". You cant's store everything in database. jQuery helps us to modify the data at the page load time.

I modified some script that helps you to turn your normalized text links to hyperlinks at load time. You can also add required information on that. Lets see how you can achieve this.

Regular Expression

Regular expression is machine language. It filter given input based on regular expression. For more information on regular expression read

Now let me tell you how you can use this javascript. If you want to convert the normalized links into hyperlinks use it as below.

<div id="links">
<script type="text/javascript">
<script type="text/javascript" src=""></script>
<script type="text/javascript" src="doLinks.js"></script>
//doLinks.js is javascript file you need to create using the below javascript code

/* doLinks.js */
function linkify(hashTagFlag,inputText, options) { 
this.options = { linkClass: 'url', targetBlank: true }; 
this.options = $.extend(this.options, options); 
inputText = inputText.replace(/\u200B/g, ""); 

var replacePattern1 = /(name="[.\\/#a-zA-Z0-9\\(]*|id="[#a-zA-Z0-9\(]*|src="[#a-zA-Z0-9\\(]*|href="[#a-zA-Z0-9\(]*|">|\s>)?(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;ï]*[-A-Z0-9+&@#\/%=~_|ï]/gim; 
var replacedText = inputText.replace(replacePattern1, function($0,$1){ 
    return $1?$0:'<a class="'+ this.options.linkClass + '" href="' + $0 + '"target="_blank">'+ $0+ '</a>'; 

var replacePattern2 = /(|name="[.\\/#a-zA-Z0-9\\(]*|id="[#a-zA-Z0-9\(]*\(|src="[#a-zA-Z0-9\\(]*\\(|href="[#a-zA-Z0-9\(]*|">|\s>|https?:\/\/|ftp:\/\/)?www\.[-A-Z0-9+&@#\/%?=~_|!:,.;ï]*[-A-Z0-9+&@#\/%=~_|ï]/gim;
var replacedText = replacedText.replace(replacePattern2, function($0,$1){ 
    return $1?$0:'<a class="'+ this.options.linkClass + '" href="http://' + $0 + '"target="_blank">'+ $0+ '</a>';

var bold = /\*\*(.*?)\*\*/gim; 
var replacedText = replacedText.replace(bold, function($0,$1){ 
    return $1 ? ('<b>' + $1 + '</b>') : $0; 

var Italic = /\*(.*?)\*/gim; 
var replacedText = replacedText.replace(Italic, function($0,$1){
    return $1 ? ('<i>' + $1 + '</i>') : $0; 

var Strike = /\--(.*?)\--/gim; 
var replacedText = replacedText.replace(Strike, function($0,$1){ 
    return $1 ? ('<strike>' + $1 + '</strike>') : $0; 
//Works only when you pass true for hashTag
var hashTag = /#(\w*[a-zA-Z_]+\w*)/gim; 
var replacedText = replacedText.replace(hashTag, function($0,$1){ 
    return $1 ? ('<a  href="seach.jsp?query='+$0+'>"' + $0 + '</a>') : $0; 

var replacePattern3 = /([\.\w]+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim; 
var replacedText = replacedText.replace(replacePattern3, '<a class="' + this.options.linkClass + '" href="mailto:$1">$1</a>'); 
return replacedText; 
$.fn.doLinks = function(hashTagFlag){

This script works for the below scenario as well. Other scripts can't handle this input.
<a name="9552138821viruddh7(" href="viruddh7(" onclick=" playmedia(" id="viruddh7(">viruddh7(</a>