I have textBox which accept alphabeti want to validate the textBox contain proper Drive Path or not using javascript
ex:Suppose Textbox contain 'D:\' then it's valid or else it's invalid...I need to check textbox contain ':\' or not after alphabet
plz help me
try to use javascript method "replace" http://www.w3schools.com/jsref/jsref_replace.asp to remove unwanted contents.
You can use following regex
/^(\\(\\[^\s\\]+)+|([A-Za-z]:(\\)?|[A-z]:(\\[^\s\\]+)+))(\\)?$/
Related
I am trying to write a regular expression or regex for my HTML input field with text type. The user should enter the URI in the input field. The URI would look something like this: urn:URNNamespace:**:class:ObjClassid.
Some of the examples of valid URI are as follows:
urn:abc:testing:pqrs:1234556.1244
urn:wxyz:testing123:abc:1234556.*
urn:global:standard:value:myvalue
I was trying to check only if the initial characters are URN using the expression ^(urn):// and check if the string contains the character : in it.
I just want to make sure that user enters valid URN similar to the one that's provided. Is there any better way I can use and achieve this?
I would recommend a really great tool called Regulex that helps you build regular expressions.
I tried to create the described pattern and ended up with:
^urn:\w+:\w+:\w+:\d+(\.\d+)?$
You can try and change it here
I am trying to make my form validation work but I somehow can't make my name field to validate properly. When I write names in the field it will say that I need to write a proper name. What am I doing wrong? HTML: http://pastebin.com/EfNSkQkS JavaScript: http://pastebin.com/c6iUCYvr
You simply forgot to add the + sign at the end of your letters RegExp. i. e. var reg_letters = /^[A-ZÆØÅa-zæøå]$/; should be var reg_letters = /^[A-ZÆØÅa-zæøå]+$/;
It's a problem with your regex expression in your javascript code var reg_letters = /^[A-ZÆØÅa-zæøå]$/; I don't know what other characters you want to allow
But when i changed it this -->var reg_letters = /^[a-zA-Z]*$/; it works(this regex expression is for English Characters only.
This is a plunker link to test it, just change them (var reg-letters) to test. plunkr link
*Note i removed the action and method from the form, so plunkr doesn't throw errors.
I am new to javascript and I couldn't find the exact code for my need.
I want a text field with maxlength="5" which should look like ex:AE456, LM975. i.e., the first two letters ahould be alphabets and next three letters should be numbers.
the text area should accept input according to this pattern only. I don't want any alert. Simply it has to accept whatever typed only in this pattern.
Javascript is preferrable. Any help is greatly appreciable.
Thanks in advance.
HTML5 supports pattern where a field can accept values as per the supplied regex. You can find related post here.
Regex Patterns for HTML5 Text Field
But if you want to support older browser, then you have to attach events like "keypress" to the input field, and handle the event to validate the input
If you have this HTML:
<input type="text" id="text1" />
Then you could use this Javascript:
function validateInput() {
var val = document.getElementById("text1").value;
return /[A-Z]{2}\d{3}/i.test(val);
}
and call it like:
if (validateInput()) {
// Matches pattern: #####
}
DEMO: http://jsfiddle.net/GgQsz/
This allows uppercase and lowercase alpha characters at the beginning. If you want to only allow uppercase, remove the i flag for the Regex.
What you need is a regular expression. Check out regular expression here. This should give you an idea as to how to check for your condition.
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
I'm using jQuery's validation plugin to validate a form.
I have a field which should only contain letters or numbers. I have tried the following regex but it's still allowing characters such as ' ; :
[a-zA-Z 0-9]$
What am I doing wrong?
Thanks in advance
Try this:
^[a-zA-Z 0-9]*$
If this is a required field, then change asterisk to plus:-
^[a-zA-Z 0-9]+$
Try this expression::
^[a-zA-Z 0-9]+$
I have this RegEx that validates input (in javascript) to make sure user didn't enter more than 1000 characters in a textbox:
^.{0,1000}$
It works ok if you enter text in one line, but once you hit Enter and add new line, it stops matching. How should I change this RegEx to fix that problem?
The problem is that . doesn't match the newline character. I suppose you could use something like this:
^[.\r\n]{0,1000}$
It should work (as long as you're not using m), but do you really need a regular expression here? Why not just use the .length property?
Obligatory jwz quote:
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
Edit: You could use a CustomValidator to check the length instead of using Regex. MSDN has an example available here.
What you wish is this:
/^[\s\S]{0,1000}$/
The reason is that . won't match newlines.
A better way however is to not use regular expressions and just use <text area element>.value.length
If you just want to verify the length of the input wouldn't it be easier to just verify the length of the string?
if (input.length > 1000)
// fail validation