# add a new article reference to database
function addnewpub() {
var year = $("input#year").val();
var articlelink = $("input#articlelink").val();
var pdflink = $("input#pdflink").val();
var reference = $("input#reference").val();
if (!!(year && articlelink && pdflink && reference)) {
if (! isURL(articlelink) ){
$(this).next('.status').html("Article Link Invalid");
$(this).next('.status').css('color', '#F50162');
$('input#articlelink').focus().css('box-shadow','0 0 12px #FEBB2D inset');
return;
}
if (!pdflink.match(/https?:\/\/renlab\.fudan\.edu\.cn\/renlab\/.*\.pdf$/)) {
$(this).next('.status').html("PDF Link Invalid");
$(this).next('.status').css('color', '#F50162');
$('input#pdflink').focus().css('box-shadow','0 0 12px #FEBB2D inset');
return;
}
if (!year.match(/^[2-3][0-9][0-9][0-9]$/)) {
$(this).next('.status').html("Year Invalid");
$(this).next('.status').css('color', '#F50162');
$('input#year').focus().css('box-shadow','0 0 12px #FEBB2D inset');
return;
}
if (! (reference.match(/Ren\s+G[*#]?/) &&
( reference.match(/(\(\d{4}\)(?:\s+)?(?:[^\.]+\.)(?:\s+)?)([A-Za-z ]+)(\.?(?:\s+)?)/) ||
reference.match(/(\(\d{4}\)(?:\.)?(?:\s+)?(?:[^\.]+\.)(?:\s+)?)([A-Za-z \.]+\.?)((?:\s+)?(?:DOI|doi))/) ) ) ){
$(this).next('.status').html("Reference Invalid");
$(this).next('.status').css('color', '#F50162');
$('input#reference').focus().css('box-shadow','0 0 12px #FEBB2D inset');
return;
}
var newref = reference.replace(/Ren\s+G[*#]?/, "<span class='gd_r'>$&</span>");
newref = newref.replace(/(\(\d{4}\)(?:\s+)?(?:[^\.]+\.)(?:\s+)?)([A-Za-z ]+)(\.?(?:\s+)?)/, "$1<span class='gd_r'>$2</span>$3");
reference = newref.replace(/(\(\d{4}\)(?:\.)?(?:\s+)?(?:[^\.]+\.)(?:\s+)?)([A-Za-z \.]+\.?)((?:\s+)?(?:DOI|doi))/, "$1<span class='gd_p'>$2</span>$3");
$(this).next('.status').after("<div class='preview'></div>").html(reference); $.get('/wp-content/themes/yusi1.0/misc/addnewpub.php', {
'year': year,
'articlelink': articlelink,
'pdflink': pdflink,
'reference': reference
}).done(function(data) {
$(this).next('.status').html('Added Success');
$(this).next('.status').css('color', '#01B0F5');
$("input#year").val(date('o'));
$("input#articlelink").val(' ');
$("input#pdflink").val(' ');
$("input#reference").val(' ');
});
}
else {
$(this).next('.status').html("Invaid Input, all Required");
$(this).next('.status').css('color', '#F50162');
}
}

Javascript Regexp match and replace的更多相关文章

  1. JavaScript中String对象的match()、replace() 配合正则表达式使用

    正则表达式由来已久,查找替换功能非常强大,但模板难记复杂. JavaScript中String对象的match().replace()这2个方法都要使用正则表达式的模板.当模板内容与字符串不相匹配时, ...

  2. JavaScript中字符串的match与replace方法

    1.match方法 match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配. match()方法的返回值为:存放匹配结果的数组. 2.replace方法 replace() 方 ...

  3. JavaScript RegExp 基础详谈

    前言: 正则对于一个码农来说是最基础的了,而且在博客园中,发表关于讲解正则表达式的技术文章,更是数不胜数,各有各的优点,但是就是这种很基础的东西,如果我们不去真正仔细研究.学习.掌握,而是抱着需要的时 ...

  4. JavaScript中String.prototype.replace() 方法的使用

    摘抄于:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/replace ...

  5. JavaScript RegExp Object 正则表达式入门

    什么是 RegExp? RegExp 是regular expression的缩写. RegExp 对象表示正则表达式,它是对字符串执行模式匹配的强大工具. 当您检索某个文本时,可以使用一种模式来描述 ...

  6. [转]JavaScript RegExp 对象参考手册

    JavaScript RegExp 对象参考手册 RegExp 对象 RegExp 对象表示正则表达式,它是对字符串执行模式匹配的强大工具. 直接量语法 /pattern/attributes 创建 ...

  7. 【timeisprecious】【JavaScript 】JavaScript RegExp 对象

    JavaScript>RegExp正则表达式 1 .From Runnob JavaScript RegExp 对象(概览) JavaScript RegExp 对象(教程) RegExp 对象 ...

  8. JavaScript RegExp 正则表达式基础详谈

    前言: 正则对于一个码农来说是最基础的了,而且在博客园中,发表关于讲解正则表达式的技术文章,更是数不胜数,各有各的优点,但是就是这种很基础的东西,如果我们不去真正仔细研究.学习.掌握,而是抱着需要的时 ...

  9. 浏览器端-W3School-JavaScript:JavaScript RegExp 对象

    ylbtech-浏览器端-W3School-JavaScript:JavaScript RegExp 对象 1.返回顶部 1. JavaScript RegExp 对象 RegExp 对象 RegEx ...

随机推荐

  1. C# GridControl 行背景颜色

    使用C# DevExpress_gridControl 行号行样式显示行背景颜色,必须取消自动变换行色属性 取消Focus变色,属性为OptionSelection--EnableAppearance ...

  2. SQL Update实现使用一个表的数据更新另一张表

    表结构 功能 SQL Serevr Access 表结构

  3. DLL项目报错:fatal error lnk1104: cannot open file "...\xxx.dll"

    在生成DLL的时候报这个错, 生成不了DLL 检查生成DLL的路径是否有其他程序在使用... 或者把杀毒软件关了试试...

  4. 布置theano(Windows10,无cuda)

    软件包准备 1.Anaconda 下载地址,包含python.numpy.scipy.nose.pip等包,嗯,很爽. 2.tdm64-gcc 下载地址,windows下的gcc.g++编译器,用来t ...

  5. mysql:sql行列转换

    今天一个同学遇到一个问题问我了,由于本人平时学习的mysql比较基础,确实没解决,后来google了一下,才知道是sql的一种技法[行列转换],话不多说先上图: 想得到下面的结果: +------+- ...

  6. PL/SQL Developer连接到Oracle 12c

    安装32位的Oracle客户端instantclient-basic-nt-12.1.0.1.0.zip 下载地址:http://www.oracle.com/technetwork/topics/w ...

  7. 用 mCustomScrollbar 滚动条插件实现滚动更新添加数据

    在公司的一个小项目中,需要从后台获取一大堆数据,为了用户体验的考虑,需要分部加载,然后就在网上找了很多的滚动插件,终于找到一个合适的.mCustomScrollbar插件地址 点击这里 它有各种各样的 ...

  8. node.js学习(1)

    新建便笺 3 node.js学习(1) 1)安装 http://nodejs.org/download/下载. 2)编写一个案例 var http=require("http"); ...

  9. PostgreSQL/bin

    pg_receivexlog pg_receivexlog—以流的方式从一个PostgreSQL集簇得到事务日志 pg_receivexlog被用来从一个运行着的PostgreSQL集簇以流的方式得到 ...

  10. Google 推出的 Java 编码规范(转)

    原文地址:http://www.dahuatu.com/1225/988516.html 原文地址:http://www.dahuatu.com/1225/988516.html 原文地址:http: ...