Formatting Data in Textbox to $###,###,###,##0.00 - jquery-ui

I have a textbox where I always want data in $###,###,###,##0.00 format (like $25.00 ). Now on typing some data i want to get the same format . For ex if i type 25 it should convert to $25.00 and if i input 'as23afs' (characters) it should convert to $0.00 . How can i do it? Please suggest a solution. If I can make use of Regular expressions how can i do it?

Take a look at those plugins:
http://digitalbush.com/projects/masked-input-plugin/
http://www.meiocodigo.com/projects/meiomask/
http://www.decorplanit.com/plugin/

i was facing the same issue now i fixed that by set the textbox custom Format:
use this code in KeyPress Event :
private void yourtextbox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 && e.KeyChar != ',' && e.KeyChar != '$') // 8 is back space
{
if (e.KeyChar == (char)13) // 13 is Enter
{
yourtextbox.Text = string.Format("${0:#,##0.00}", double.Parse(yourtextbox.Text));
}
}
}
Now your Textbox accept only numbers and ',' and '$'
now if you input 'as23afs' (characters) it should convert to $0.00 .
use this code :
yourtextbox.Text = double.Parse("0").ToString("N2");//"N2" to show 00 after ','.
i think that's all i hope this code help everyone looking for currency Format in textbox .
so the complete code should be like that :
public Form1()
{
InitializeComponent();
yourtextbox.Text = double.Parse("0").ToString("N2");//"N2" to show 00 after ','
}
private void yourtextbox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 && e.KeyChar != ',' && e.KeyChar != '$') // 8 is back space
{
if (e.KeyChar == (char)13) // 13 is Enter
{
yourtextbox.Text = string.Format("${0:#,##0.00}", double.Parse(yourtextbox.Text));
}
}
}

Related

Empty FullText property with Tweetmode.Extended [update May 30th]

I'm programming a .Net Core (2.1 preview, C# 7.3) Streaming Console App with L2T (5.0.0 beta 2) but even with the strm.TweetMode == TweetMode.Extended the query gives "compat" tweets back, the FullText property is empty.
You can reproduce this with the L2T query below.
I searched online, I've found something similar (with 'search' instead of 'Streaming') but no answers, except to add && strm.TweetMode == TweetMode.Extended, which I did.
Any ideas?
try
{
await
(from strm in twitterCtx.Streaming
.WithCancellation(cancelTokenSrc.Token)
where
strm.Type == StreamingType.Filter
&& strm.Track == "twitter"
&& strm.Language == "nl"
&& strm.TweetMode == TweetMode.Extended
select strm)
.StartAsync(async strm =>
{
await HandleStreamResponse(strm);
if (count++ >= 20)
cancelTokenSrc.Cancel();
});
}
[Update May 30th]
Found something. It's in the subroutine "HandleStreamResponse" (code below). The Status.TweetMode and Status.ExtendedTweet.TweetMode both return "Compat" for all tweets, but the full text of a tweet is in status.ExtendedTweet.FullText
But even with this check, retweets are truncated to 140 chars max. I do not need retweets for my progam so I filter them out.
I do not know, yet, how to filter retweets from a stream directly (is it possible?), so I check the retweetstatus of the Status from the stream result. It's in the code below.
FYI: In the examples of Linq To Twitter for this subroutine Joe Mayo uses the following line of code, but that doesn't work: Console.WriteLine("{0}: {1} {2}", status.StatusID, status.User.ScreenNameResponse, status.Text ?? status.FullText);
Even with && strm.TweetMode == TweetMode.Extended in the L2T query, the status.FullText is empty.
There is more code than neccesary in the example below, but I used it for clarity.
static async Task<int> HandleStreamResponse(StreamContent strm)
{
switch (strm.EntityType)
{
case StreamEntityType.Status:
var status = strm.Entity as Status;
if (status.RetweetedStatus.StatusID == 0)
{
if (status.ExtendedTweet.FullText != null)
{
Console.WriteLine("Longer than 140 - \"#{0}\": {1} (TweetMode:{2})",
status.User.ScreenNameResponse, status.ExtendedTweet.FullText, status.TweetMode);
}
else
{
Console.WriteLine("Shorter than 140 - \"#{0}\": {1} (TweetMode:{2})",
status.User.ScreenNameResponse, status.Text, status.TweetMode);
}
}
// Console.WriteLine("{0}: {1} {2}", status.StatusID, status.User.ScreenNameResponse, status.Text ?? status.FullText);
break;
default:
Console.WriteLine("Unknown - " + strm.Content + "\n");
break;
}
return await Task.FromResult(0);
}
}
Here are my observations:
status.ExtentendedTweet.FullText should hold the tweet in normal circumstances.
However, if the tweet is retweeted, then status.RetweetedStatus.ExtendedTweet.FullText should hold the tweet.
If you can't find the FullText in either of those circumstances, use status.Text.
I'm updating the sample with the following:
case StreamEntityType.Status:
var status = strm.Entity as Status;
string text = null;
if (status.ExtendedTweet?.FullText != null)
text = status.ExtendedTweet?.FullText;
else if (status.RetweetedStatus?.ExtendedTweet?.FullText != null)
text = status.RetweetedStatus?.ExtendedTweet?.FullText;
else
text = status.Text;
Console.WriteLine("Status - #{0}: {1}", status.User.ScreenNameResponse, text);
break;
Note: Via Twitter documentation (see Standard Streams), TweetMode doesn't apply to streams. Additionally, the docs say the ExtentedTweet should always be there with FullText. As we can see, that isn't the full picture in practice. I'll mark Streaming.TweetMode as obsolete in upcoming releases.

Only accept numerics characters in textbox

I try to do a things very easy but it doesn't works...
I want my textbox accepts only numerics characters. I found a lot of parts of code on internet but none working...
I try this code for example :
private void TxtNumPoste_TextChanged(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
TxtNumPoste is the name of my TextBox.
Is a person sees an error ?
Thanks for your help.

Check if some value already exist in database ASP.NET MVC?

How can I check if some value already exist in database I am doing MVC with Entity Framework and I want to check if element with composite key already exist in database application does someone has any suggestion i GOT the Json object but my done() method doesn't work?
I tried with JsonResult method from my controller
public JsonResult Check(int? id1, int? id2)
{
IQueryable<InspekcijskaKontrola> listaKontrola = db.InspekcijskeKontrole.Include(i => i.InspekcijskaTijela).Include(i => i.Proizvod).Select(i => i);
InspekcijskaKontrola inKontrola = listaKontrola.Where(i => i.InspekcijskoTijeloId == id1).Where(i => i.ProizvodId == id2).Select(i => i).Single();
if (inKontrola!=null)
{
return Json(inKontrola, JsonRequestBehavior.AllowGet);
}
return Json(new InspekcijskaKontrola { InspekcijskoTijeloId = -1, ProizvodId = -1 }, JsonRequestBehavior.AllowGet);
}
And I tried to rised modal dialog from my view with script
function prikazi() {
var zahtjev = $.getJSON("/InspekcijskeKontrole/Check?id1=" + $("#kombo3").val() + "&id2=" + $("#kombo4").val());
zahtjev.done(function (kontrola) {
if (kontrola.InspekcijskoTijeloId != -1 && kontrola.ProizvodId != -1) {
$("#p1").text("Inspekcijska kontrola za " + kontrola.ProizvodId + " je vec izvrsena");
$("#modalni1").modal({ backdrop: "static" });
}
});
}
Providing a bit of code would really help. However, right off the bat I could suggest you use something like this to search for a key(or more) from an object:
if(dbContext.Items.Any(anyObjectName=>anyObjectName.firstKey == ValueYouLookFor
&& anyObjectName.secondkey == AnotherValue))
{
//logic to apply if object exists
}

Display result matching optgroup using select2

I'm using select2 with Bootstrap 3.
Now I would like to know whether it is possible to display all optgroup items if the search matches the optgroup name while still being able to search for items as well. If this is possible, how can I do it?
The above answers don't seem to work out of the box with Select2 4.0 so if you're hunting for that, check this out: https://github.com/select2/select2/issues/3034
(Use the function like this: $("#example").select2({matcher: modelMatcher});)
function modelMatcher (params, data) {
data.parentText = data.parentText || "";
// Always return the object if there is nothing to compare
if ($.trim(params.term) === '') {
return data;
}
// Do a recursive check for options with children
if (data.children && data.children.length > 0) {
// Clone the data object if there are children
// This is required as we modify the object to remove any non-matches
var match = $.extend(true, {}, data);
// Check each child of the option
for (var c = data.children.length - 1; c >= 0; c--) {
var child = data.children[c];
child.parentText += data.parentText + " " + data.text;
var matches = modelMatcher(params, child);
// If there wasn't a match, remove the object in the array
if (matches == null) {
match.children.splice(c, 1);
}
}
// If any children matched, return the new object
if (match.children.length > 0) {
return match;
}
// If there were no matching children, check just the plain object
return modelMatcher(params, match);
}
// If the typed-in term matches the text of this term, or the text from any
// parent term, then it's a match.
var original = (data.parentText + ' ' + data.text).toUpperCase();
var term = params.term.toUpperCase();
// Check if the text contains the term
if (original.indexOf(term) > -1) {
return data;
}
// If it doesn't contain the term, don't return anything
return null;
}
Actually found the solution by modifying the matcher opt
$("#myselect").select2({
matcher: function(term, text, opt){
return text.toUpperCase().indexOf(term.toUpperCase())>=0 || opt.parent("optgroup").attr("label").toUpperCase().indexOf(term.toUpperCase())>=0
}
});
Under the premise that the label attribute has been set in each optgroup.
Found a solution from select2/issues/3034
Tested with select2 v.4
$("select").select2({
matcher(params, data) {
const originalMatcher = $.fn.select2.defaults.defaults.matcher;
const result = originalMatcher(params, data);
if (
result &&
data.children &&
result.children &&
data.children.length
) {
if (
data.children.length !== result.children.length &&
data.text.toLowerCase().includes(params.term.toLowerCase())
) {
result.children = data.children;
}
return result;
}
return null;
},
});
A few minor changes to people suggested code, less repetitive and copes when there are no parent optgroups:
$('select').select2({
matcher: function(term, text, opt){
var matcher = opt.parent('select').select2.defaults.matcher;
return matcher(term, text) || (opt.parent('optgroup').length && matcher(term, opt.parent('optgroup').attr("label")));
}
});

How to move the textbox cursor to the last index of text?

I have a text box where the user can enter details up to 140 characters after that a dialog box pop up which showing maximum limit reached .My problem is that after the message box is shown the cursor is blinking at the beginning of the text.and also further typing is possible.I have to do two things one is the cursor should blinking at the end of text after message box shown.and next is when the user hit characters more than 140 it should not be entered in the text box.?Please give me a solution for this
Here is my code.
private void tbMessage_TextChanged(object sender, TextChangedEventArgs e)
{
string txt = tbMessage.Text;
Regex regx = new Regex("\\(?\\b(http|https)://([-A-Za-z0-9+&##/%?=~_()|!:,.;\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]*[-A-Za-z0-9+&##/%=~_()|])");
regx.Matches(txt);
MatchCollection mactches = regx.Matches(txt);
foreach (Match match in mactches)
{
txt = txt.Replace(match.Value, "<--------------------->");
}
textBlockNumberLimit.Text = txt.Length.ToString() + "/140";
if (txt.Length > 140)
{
try
{
MessageBox.Show("Maximum limit reached", "SPRINKLR", MessageBoxButton.OK);
tbMessage.Text = tbMessage.Text.Substring(0, tbMessage.Text.Length - 1);
}
catch
{
}
}
}

Resources