Hi have some forms that I want to use some basic php validation (regular expressions) on, how do you go about doing it? I have just general text input, usernames, passwords and date to validate. I would also like to know how to check for empty input boxes. I have looked on the interenet for this stuff but I haven't found any good tutorials.
Thanks
Hi all,
I am doing some self learning about Patern Matching in Javascript.
I got a simple input text field in a HTML web page,
and I have done some Javascript to capture the string and check if there
are any strange characters other than numbers and characters in the string.
But I am not sure if it is correct.
Only numbers, characters or a mixture of numbers and characters are allowed.
var pattern = /^[a-z]+|[A-Z]+|[0-9]+$/;
And I have another question about Pattern Matching in Javascript,
what does the percentage symbol mean in Pattern matching.
For example:
var pattern = '/[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/';
Hi all, lets say I have a string that I want to split based on several characters, like ".", "!", and "?". How do I figure out which one of those characters split my string so I can add that same character back on to the end of the split segments in question?
Dim linePunctuation as Integer = 0
Dim myString As String = "some text. with punctuation! in it?"
For i = 1 To Len(myString)
If Mid$(entireFile, i, 1) = "." Then linePunctuation += 1
Next
For i = 1 To Len(myString)
If Mid$(entireFile, i, 1) = "!" Then linePunctuation += 1
Next
For i = 1 To Len(myString)
If Mid$(entireFile, i, 1) = "?" Then linePunctuation += 1
Next
Dim delimiters(3) As Char
delimiters(0) = "."
delimiters(1) = "!"
delimiters(2) = "?"
currentLineSplit = myString.Split(delimiters)
Dim sentenceArray(linePunctuation) As String
Dim count As Integer = 0
While linePunctuation > 0
sentenceArray(count) = currentLineSplit(count)'Here I want to add what ever delimiter was used to make the split back onto the string before it is stored in the array.'
count += 1
linePunctuation -= 1
End While
I am have completed javascript validation of a form using Regular Expressions and am now working on redundant verification server-side using PHP.
I have copied this regular expression from my jscript code that finds dollar values, and reformed it to a PHP friendly format:
/\$?((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/
Specifically:
if (preg_match("/\$?((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/", $_POST["cost"])){}
While the expression works great in javascript I get :
Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1
when I run it in PHP. Anyone have a clue why this error is coming up?
if (preg_match('(\p{Nd}{4}/\p{Nd}{2}/\p{Nd}{2}/\p{L}+)', '2010/02/14/this-is-something'))
{
// do stuff
}
The above code works. However this one doesn't.
if (preg_match('/\p{Nd}{4}/\p{Nd}{2}/\p{Nd}{2}/\p{L}+/u', '2010/02/14/this-is-something'))
{
// do stuff
}
Maybe someone could shed some light as to why the one below doesn't work. This is the error that is being produced:
A PHP Error was encountered
Severity: Warning
Message: preg_match()
[function.preg-match]: Unknown
modifier '\'
I want to break a Python string into its characters.
sequenceOfAlphabets = list( string.uppercase )
works.
However, why does not
sequenceOfAlphabets = re.split( '.', string.uppercase )
work?
All I get are empty, albeit expected count of elements
I have a string like this:
<![CDATA[<ClinicalDocument>rest of CCD here</ClinicalDocument>]]>
I'd like to replace the escape sequences with their non-escaped characters, to end up with:
<![CDATA[<ClinicalDocument>rest of CCD here</ClinicalDocument>]]>
Hi There,
Does anyone have a regurlar expression available which only accepts dates in the format dd/mm/yy but also has strict checking to make sure that the date is valid, including leap year support?
I am coding in vb.net and am struggling to work this one out.
Many Thanks
I am very very very new to C# and ASP.NET development.
What I'd like to do is a find-and-replace for certain words appearing in the body text of a web page. Every time a certain word appears in the body text, I'd like to convert that word into a hyperlink that links to another page on our site.
I have no idea where to even start with this. I've found code for doing find-and-replace in C#, but I haven't found any help for just reading through a document, finding certain strings, and changing them into different strings.
For example, if I'm doing some form input validation and I'm using the following code for the name field.
preg_match("/^[a-zA-Z .-]$/", $firstname);
If someone types in Mr. (Awkward) Double-Barrelled I want to be able to display a message saying Invalid character(s): (, )
I want to have a function which gets a text as the input and gives back the text with URLs made to HTML links as the output.
My draft is as follows:
function autoLink($text) {
return preg_replace('/https?:\/\/[\S]+/i', '<a href="\0">\0</a>', $text);
}
But this doesn't work properly.
For the input text which contains ...
http://www.google.de/
... I get the following output:
<a href="http://www.google.de/<br">http://www.google.de/<br</a> />
Why does it include the line breaks? How could I limit it to the real URL?
Thanks in advance!
I have read the other posts, e.g., http://stackoverflow.com/questions/1830886/vim-executing-a-list-of-editor-commands and others. The answer isn't clear to me for my case. I have some editor commands that I generated from an SQL query. It uses :s/foo/bar to change country codes (from FIPS to a non-standard code set). Here's a sample of the file:
:s/CB/CAMBO
:s/CQ/NMARI
:s/KV/KOSOV
:s/PP/PAPUA
...
I have saved that in a file called fipsToNonStd.vim (unsure about the correct extension). I want to run those commands one after another. What's the easiest way to do so?
Thanks a bunch! SO Rocks!
Sorry if this has been asked, my search brought up many off topic posts.
I'm trying to convert wildcards from a user defined search string (wildcard is "*") to postgresql like wildcard "%".
I'd like to handle escaping so that "%" => "\%" and "\*" => "*"
I know i could replace \* with something else prior to replacing * and then swap it back, but i'd prefer not to and instead only convert * using a pattern that selects it when not proceeded by \.
String convertWildcard(String like)
{
like = like.replaceAll("%", "\\%");
like = like.replaceAll("\\*", "%");
return like;
}
Assert.assertEquals("%", convertWildcard("*"));
Assert.assertEquals("\%", convertWildcard("%"));
Assert.assertEquals("*", convertWildcard("\*")); // FAIL
Assert.assertEquals("a%b", convertWildcard("a*b"));
Assert.assertEquals("a\%b", convertWildcard("a%b"));
Assert.assertEquals("a*b", convertWildcard("a\*b")); // FAIL
ideas welcome.
I'm trying to parse various info from log files, some of which is placed within square brackets. For example:
Tue, 06 Nov 2007 10:04:11 INFO processor:receive: [someuserid], [somemessage] msgtype=[T]
What's an elegant way to grab 'someuserid' from these lines, using sed, awk, or other unix utility?
Is there a way (using XPath and PHP) to do the following (WITHOUT external XSLT files)?
Remove all tables and their contents
Remove everything after the first h1 tag
Keep only paragraphs (INCLUDING their inner HTML (links, lists, etc))
I received an XSLT answer here, but I'm looking for XPATH queries that don't require external files.
Currently, I've got the HTML in question loaded into a SimpleXmlElement via:
$doc = @DOMDocument::loadHTML($xml);
$data = simplexml_import_dom($doc);
Now I need help with:
$data = $data->xpath('??????');
Been working with this one for several days to no avail. I really appreciate the help.
Edit: I don't particularly care what's inside the paragraphs, as I can use strip_tags to eliminate what I don't want. All I need to do is to isolate the paragraphs from the rest of the source. I suppose a more specific, accurate requirement would be this:
Return only paragraphs (and their html contents) that aren't contained in tables, and only before the first h1 tag
What is wrong with this regexp? I need it to make $name to be letter-number only. Now it doens't seem to work at all.
if (!preg_match("/^[A-Za-z0-9]$/",$name)) {
$e[]="name must contain only letters or numbers";
}
I have a lot lines contains XXXXXXXXX number format. I want change number XXXXXXXXX to XX.XXX.XXX.X
XXXXXXXXX = 9 digit random number
Anyone can help me? Thanks in advance
Dont ask how this works but currently it does ("^\|(.?)\|*$")....kinda. This removes all extra pipes...part one....I have searched all over no anwser yet. I am using VB2011 beta...asp web form......vb coding though!
I want to capture special character pipe (|) which is used to seperate words...i.e. car|truck|van|cycle
problem is users lead with, trail with, use multiple, and use spaces before and after...i.e. |||car||truck | van || cycle.
another example: george bush|micheal jordon|bill gates|steve jobs <-- this would be correct but when I do remove space it takes correct space out.
so I want to get rid of whitespace leading, trailing, any space before | and space after | and only allow one pipe (|)....in between alphanumeric of course.
What will be proper regular expression for git repositories?
example link:
[email protected]:someone/someproject.git
so it will be like
server can be url or ip
Project can contain some other characters than alphanumeric like '-'
I'm not sure what is the role of '/'
any suggestions?
I need regular expression to match braces correct e.g for every open one close one
abc{abc{bc}xyz} I need it get all it from {abc{bc}xyz} not get {abc{bc} I tried this
({.*?})
I am trying to parse a file generated by LGA Tracon that lists the position data for aircraft over a given time frame. The data of interest starts with TRACKING DATA and ends with SST and there are thousands of entries per file. The system generating the file, Common ARTS, is very rigid in its formatting and we can expect the column spacing to be consistent. Any help would be greatly appreciated.
Thanks,
Here is an image to preserve the exact formatting
Here is a reduced text file.
link text
I'm using GNU Make 3.81, and I have the following rule in my Makefile:
jslint :
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint at line \([0-9]\+\) character \([0-9]\+\)/mango.js:\1:\2/'
This works fine if I enter it directly on the command line, but the regular expression does not match if I run it with "make jslint". However, it works if I replace \+ with \{1,\} in the Makefile:
jslint :
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint at line \([0-9]\{1,\}\) character \([0-9]\{1,\}\)/mango.js:\1:\2/'
Is there some special meaning to \+ in Makefiles, or is this a bug?